From d71ac35d72529d3dee08d9591cd1c65cbdcccb6d Mon Sep 17 00:00:00 2001 From: David Pedersen Date: Thu, 5 Dec 2013 12:43:13 +0100 Subject: [standard-ml/en-en] infix functions --- standard-ml.html.markdown | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) 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 -- cgit v1.2.3