summaryrefslogtreecommitdiffhomepage
path: root/standard-ml.html.markdown
diff options
context:
space:
mode:
authorDavid Pedersen <david.pdrsn@gmail.com>2013-12-05 12:43:13 +0100
committerDavid Pedersen <david.pdrsn@gmail.com>2013-12-05 12:43:13 +0100
commitd71ac35d72529d3dee08d9591cd1c65cbdcccb6d (patch)
treec4931c7eefadb803a0710f4ad637059ae95c7823 /standard-ml.html.markdown
parentacc2dda568ac3bad9173a1cf3f114905a102d893 (diff)
[standard-ml/en-en] infix functions
Diffstat (limited to 'standard-ml.html.markdown')
-rw-r--r--standard-ml.html.markdown18
1 files changed, 18 insertions, 0 deletions
diff --git a/standard-ml.html.markdown b/standard-ml.html.markdown
index 9de31340..849ba0f5 100644
--- a/standard-ml.html.markdown
+++ b/standard-ml.html.markdown
@@ -264,6 +264,24 @@ fun map f [] = []
(* map has type ('a -> 'b) -> 'a list -> 'b list and is called polymorphic. *)
(* 'a is called a type variable. *)
+
+(* We can define functions as infix *)
+fun plus (x, y) = x + y
+infix plus
+(* We can now call plus like "2 plus 5" *)
+
+(* Functions can also be made infix before they are defined *)
+infix minus
+fun x minus y = x - y
+
+(* An infix function/operator can be made prefix with "op" *)
+val n = op + (5, 5)
+(* n is now 10 *)
+
+(* op is useful when combined with high order functions *)
+val listSum = foldl op + 0 [1,2,3,4,5]
+
+
(* Datatypes are useful for creating both simple and complex structures *)
datatype color = Red | Green | Blue