Penguin

Differences between version 18 and predecessor to the previous major change of ML.

Other diffs: Previous Revision, Previous Author, or view the Annotated Edit History

Newer page: version 18 Last edited on Monday, February 24, 2003 4:42:52 pm by GlynWebster Revert
Older page: version 17 Last edited on Monday, February 24, 2003 4:16:44 pm by GlynWebster Revert
@@ -3,9 +3,9 @@
 ''(Tutorial's are good, this is supposed to be an interesting place to go and learn stuff from, however, not all these concepts are exclusively ML, for instance StaticallyTyped, HigherOrder, PolyMorphic, Functional, StandardisedLanguage, are all attributes of other programming languages too, breaking these out into their own pages would be educational no? -- PerryLorier)'' 
  
 !!!ML in one paragraph, with buzzwords: 
  
-ML is a family of StaticallyTyped[1], [strict | StrictEvaluation] [4] [higher-order | HigherOrderFunctions][2] , polymorphic[3], [FunctionalLanguage]s with and a higher-order module system[5]. ML is very good general purpose programming language[6] with a strength in pattern matching[7]. ML can be used interactively for learning, experimentation and testing, or it can be compiled. The two major dialects of ML are [Ocaml] and [SML]. SML is a standardised language[8] with several implementations[9]. Ocaml has a single open source implementation[10], it extends ML with an OOP system[11]. Both major dialects have compilers that produce native code that rivals the speed of C++, and extensive standard[12] and third-party[13] libraries. 
+ML is a family of StaticallyTyped[1] [FunctionalLanguage]s with StrictEvaluation[4], PolyMorpicTypes, HigherOrderFunctions, a higher-order module system[5]. ML is very good general purpose programming language[6] with a strength in pattern matching[7]. ML can be used interactively for learning, experimentation and testing, or it can be compiled. The two major dialects of ML are [Ocaml] and [SML]. SML is a standardised language[8] with several implementations[9]. Ocaml has a single open source implementation[10], it extends ML with an OOP system[11]. Both major dialects have compilers that produce native code that rivals the speed of C++, and extensive standard[12] and third-party[13] libraries. 
  
 ''(Click a footnote for more info.)'' 
  
 !!!An example of ML code: 
@@ -39,61 +39,14 @@
 ---- 
  
 [1] ML can determine a variable's type by analyzing how it is used: you only need to declare types in places where you think it improves your code's clarity. 
  
-  
-[2]  
-!!!Polymorphism  
-  
-PolymorphicTypes are what prevents ML's strong type checking from being a pain in the bum. You don't have to define the type of everything ''exactly'', you can leave some types, or parts of some types unspecified. This allowed you write a great variety of type-safe generic functions.  
-  
-[3]  
-!!!Higher-order Functions  
-  
-Higher-order functions are functions that take other functions as parameters, create functions or return functions.  
-  
-I want make new trees from old ones by changing the leaves. So I write a function to do this for me. One of its parameters will be a function that takes the value of a leaf and returns the changed value.  
-  
- # __let rec__ map change tree =  
- __match__ t __with__  
- | Leaf value -> Leaf (change value)  
- | Node (left, right) -> Node (map change left, map change right) ;;  
- ''val map : ('a -> 'b) -> 'a tree -> 'b tree = <fun>''  
-  
-Once again Ocaml has worked out the types for itself. (__a -> b -> c__ is ML for "function that takes parameters of the types __a__ and __b__ and returns a value of type __c__.) It's also noted that if the __change__ function doesn't return the same type as its given then my __map__ function will return a tree of a different type. Good. That's what I wanted. (If it wasn't I could add some type annotations to say so.)  
-  
-Here's a function I could use as a __change__ parameter:  
-  
- # string_of_int ;;  
- ''- : int -> string = <fun>''  
-  
-You can guess what that does. __map__'s type is __('a -> 'b) -> 'a tree -> 'b tree__, so if I give it __string_of_int__ as its first parameter then __'a__ will be __string__ and __'b__ will be __int__, so __map__ should return a __string tree__...  
-  
- # __let__ numtree = Node (Node (Leaf 1, Leaf 2), Leaf 3) ;;  
- ''val numtree : int tree = Node (Node (Leaf 1, Leaf 2), Leaf 3)''  
-  
- # map string_of_int numtree ;;  
- ''- : string tree = Node (Node (Leaf "1", Leaf "2"), Leaf "3")''  
-  
-And it does!  
-  
-If I write a few more functions like this I will have a reusable library of binary tree operations. ML makes writing reusable code and easy and ''reliable'' process.  
-  
-There's a lot more things you can do with higher-order functions, some of them very painful. I've just shown you there's at least ''one'' good thing you can do with then here.  
-  
-''Higher-order functions are something ML has in common with [Haskell].''  
-  
-  
- [4]  
-!!!Strict Evaluation  
-  
- ML uses StrictEvaluation. This means that ML can allow reassignable variables and a conventional I/O system -- and it does. 
+[4] ML uses StrictEvaluation. This means that ML can allow reassignable variables and a conventional I/O system -- and it does. 
  
 ''[Haskell]'s main semantic difference from ML is that is it uses LazyEvaluation. If you enjoyed Haskell programming at WaikatoUniversity but because exasperated with [Monad]s and working out convoluted ways to make your programs preserve state, ML may be the thing for you.'' 
  
  
-[5]  
-!!! Higher-Order Module System 
+[5] The __ Higher-Order Module System__.  
  
 Modules are used to group related types, functions and classes, and to hide implementation details. The customary way to define a type in ML is to wrap it in a module with all the functions that operate on it. Optionally you can hide the definition of the type to make the module into an [AbstractDataType]. 
  
 Some modules in Ocaml's standard library just define groups of related functions, such as [Unix | http://caml.inria.fr/ocaml/htmlman/libref/Unix.html ], and some define abstract data types, such as [Hashtbl | http://caml.inria.fr/ocaml/htmlman/libref/Hashtbl.html]. 
@@ -121,10 +74,9 @@
  ''end'' 
  
 This example doesn't do anything that can't be done with polymorphic types, but the idea is that you can replace any group types, functions or classes in a module this way. 
  
-[6]  
-!!! ML is very good general purpose programming language 
+[6] __ ML is very good general purpose programming language.__  
  
 The type system means that even when I just sit down and hack, I get good quality code. 
  
 * I can leave out type definitions. This lets me program in the succinct, flexible way I can in [Python], without the let-down of having all my type errors pop up a runtime. 
@@ -135,63 +87,47 @@
  
 ''(more to say..)'' 
  
  
-[7]  
-!!!Pattern Matching  
-  
- Pattern matching is ML's strength. ML has an expression that is halfway between [C]'s__switch__ and declaration statements. In SML it is called __case__ and in Ocaml it is called __match__. Instead matching a value with single constants, like the __switch__ statement, __match__ can match values of any complexity by example, and select parts of the value to assign to variables as it does it. 
+[7] __ Pattern matching__ is ML's strength. ML has an expression that is halfway between [C]'s__switch__ and declaration statements. In SML it is called __case__ and in Ocaml it is called __match__. Instead matching a value with single constants, like the __switch__ statement, __match__ can match values of any complexity by example, and select parts of the value to assign to variables as it does it. 
  
 __Match__ statements are very clear and compact. 
  
 ''(example to come...)'' 
  
 Pattern matching is a very useful in general, but it is particularly handy in programs that manipulate complex tree-structured data, such as the parse trees in compilers. The [original ML language| http://wombat.doc.ic.ac.uk/foldoc/foldoc.cgi?ML] was designed by someone who needed to do a ''lot'' of automated algebra on statements of symbolic logic. 
  
-[8]  
-!!! SML standard  
-  
- The language and standard library of SML are formally defined in the book [Definition of Standard ML| http://mitpress.mit.edu/catalog/item/default.asp?ttype=2&tid=3874]. (This is unusually thorough.) 
+[8] __The SML standard.__ The language and standard library of SML are formally defined in the book [Definition of Standard ML| http://mitpress.mit.edu/catalog/item/default.asp?ttype=2&tid=3874]. (This is unusually thorough.) 
  
 There is a copy at the WaikatoUniversity library. 
  
-[9]  
-!!! SML Implementations 
+[9] __ SML Implementations:__  
  
 [Standard ML of New Jersey | http://cm.bell-labs.com/cm/cs/what/smlnj/] is the biggy. ''(can any one else describe it? I've not used it.)'' 
  
 [Moscow SML | http://www.dina.dk/~sestoft/mosml.html ] is a smaller, ByteCode interpreted SML that might be a better choice if you want to quickly download something to experiment with. 
  
  
-[10]  
-!!! The Ocaml Implementation 
+[10] __ The Ocaml Implementation__  
  
 There is a single OpenSource implementation of [Ocaml]. A large community of users who don't want their code broken pressure the Ocaml development team to keep new versions standard or backwards compatible. [Python] and [Perl] are developed the same way. This 
-approach works well once the community user is large enough. Ocaml's user community user has been the necessary size for many years. 
+approach works well once the community user is large enough. Ocaml's user community has been the necessary size for many years. 
  
 An interpreter for the older [Caml Light | http://caml.inria.fr/overview-caml-light-eng.html] language is still available because it can be made to work on small computers, e.g. 286 PCs. It is an subset of Objective Caml, so there is little other reason to use it. 
  
  
-[11]  
-!!! Ocaml OOP system 
+[11] One of Ocaml's extentions to the original ML language is an ObjectOrientedProgramming system. Ocaml's OOP has everything you'd expect after using [Java] or [C++]. The syntax is quite different; class declarations are much more compact.  
  
-One of Ocaml's extentions to the original ML language is an [object oriented programming system| ]. Ocaml's OOP has everything you'd expect after using [Java] or [C++]. The syntax is quite different; class declarations are much more compact.  
-  
- A big improvement is that container classes can be parametized . In C++ and Java container objects only recognise objects inside themselves as being members of the __Object__ class. You have to cast objects back the appropriate class when you remove them from the container. In Ocaml, if you want a container object to specifically contain objects that are of the class __fruitbat__, you can say so. 
+A big improvement is that container classes are [polymorphic | PolymorphicTypes] . In C++ and Java container objects only recognise objects inside themselves as being members of the __Object__ class. You have to cast objects back the appropriate class when you remove them from the container. In Ocaml, if you want a container object to specifically contain objects that are of the class __fruitbat__, you can say so. 
  
 See [Objects in Caml | http://pauillac.inria.fr/ocaml/htmlman/manual005.html] 
  
-[12]  
-!!! Standard Libraries  
-  
-The [SML Basis Library | http://cm.bell-labs.com/cm/cs/what/smlnj/doc/basis/pages/sml-std-basis.html] is said to be very well designed
+[12] __ Standard Libraries.__  
  
+The [SML Basis Library | http://cm.bell-labs.com/cm/cs/what/smlnj/doc/basis/pages/sml-std-basis.html] is said to be very well designed. %%%  
 ''The Basis library is indeed very well designed, but for SML/NJ (one of the major SML compilers) it is poorly documented, making it somewhat difficult to use. --GianPerrone'' %%% 
 ''The Basis Library pages I've linked to above seem adequate to me. Or those not what you are talking about? --GlynWebster'' 
  
 Ocaml's library is divided into: a [core library |http://caml.inria.fr/ocaml/htmlman/manual033.html], types and function available at all times; an implementation independent [standard library | http://caml.inria.fr/ocaml/htmlman/manual034.html], modules that can be imported; and set of [optional libraries | http://caml.inria.fr/ocaml/htmlman/index.html#p:library] that are either implementation dependent or special purpose. 
  
  
-[13]  
-!!! Third-Party Libraries  
-  
- [The Caml Link Database | http://www.npc.de/ocaml/linkdb/] and [The Hump | http://caml.inria.fr/humps/index.html] are the central repositories for [Ocaml] software. 
+[13] __Ocaml Third-Party Libraries:__ [The Caml Link Database | http://www.npc.de/ocaml/linkdb/] and [The Hump | http://caml.inria.fr/humps/index.html] are the central repositories for [Ocaml] software.