Penguin

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

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

Newer page: version 17 Last edited on Monday, February 24, 2003 4:16:44 pm by GlynWebster Revert
Older page: version 15 Last edited on Thursday, February 20, 2003 5:04:31 pm by GlynWebster Revert
@@ -43,34 +43,9 @@
  
 [2] 
 !!!Polymorphism 
  
-This is 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. For example this is a type for binary trees:  
-  
- # __type__ 'a tree = Leaf __of__ 'a | Node __of__ 'a tree * 'a tree ;;  
- ''type 'a tree = Leaf of 'a | Node of 'a tree * 'a tree''  
-  
-(That's me typing at the Ocaml interpreter prompt and Ocaml responding.) The type __tree__ is polymorphic: __'a__ is a place holder for any type. For example you might want a __string tree__:  
-  
- # __let__ my_tree = Node (Node (Leaf "Cow", Leaf "Pig"), Leaf "Cat") ;;  
- ''val my_tree : string tree = Node (Node (Leaf "Cow", Leaf "Pig"), Leaf "Cat")''  
-  
-The Ocaml interpreter was in fact clever enough to work that was a string tree by itself. From my tree type I can make __int trees__, __char trees__, __string tree trees__, whatever. These would all be incompatible types, because __ints__, __chars__ and __strings__ are incompatible. However, functions I write for __' a tree__s can be used on any type of tree:  
-  
- # __let rec__ count_leaves (t : 'a tree) : int =  
- __match__ t __with__  
- | Leaf _ -> 1  
- | Node (left,right) -> count_leaves left + count_leaves right ;;  
- ''val count_leaves : 'a tree -> int = <fun>''  
-  
- # count_leaves my_tree ;;  
- ''- : int = 3''  
-  
- # count_leaves (Node (Leaf 1, Leaf 2)) ;;  
- ''- : int = 2''  
-  
-Polymorphism is something ML has in common with [Haskell] .  
-  
+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 
  
@@ -153,11 +128,11 @@
 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. 
  
-* The type system is very expressive. It encourages a style of programming where you think about your data, what it consists of and how you will transform it. Programs designed by type tend to be very modular, they almost have to be by definition. 
+* The type system is very expressive. It encourages a style of programming where I think about my data, what it consists of and how I will transform it. Programs designed by type tend to be very modular -- they almost have to be by definition. 
  
-* The type system is very exact. It allowed the compiler to spot many big, logical errors at compile time, and well as the little nit-picky syntactic ones. 
+* The type system is very exact. It allows the compiler to spot many big, logical errors at compile time, and well as the little nit-picky syntactic ones. 
  
 ''(more to say..)''