diff options
Diffstat (limited to 'standard-ml.html.markdown')
| -rw-r--r-- | standard-ml.html.markdown | 10 | 
1 files changed, 7 insertions, 3 deletions
| diff --git a/standard-ml.html.markdown b/standard-ml.html.markdown index c9eb2a2e..e1fe0d19 100644 --- a/standard-ml.html.markdown +++ b/standard-ml.html.markdown @@ -1,5 +1,6 @@  ---  language: "Standard ML" +filename: standardml.sml  contributors:      - ["Simon Shine", "http://shine.eu.org/"]      - ["David Pedersen", "http://lonelyproton.com/"] @@ -351,7 +352,10 @@ val _ = print (say(Red) ^ "\n")  fun say Red   = "You are red!"    | say Green = "You are green!"    | say Blue  = "You are blue!" -  | say _     = raise Fail "Unknown color" + +(* We did not include the match arm `say _ = raise Fail "Unknown color"` +because after specifying all three colors, the pattern is exhaustive +and redundancy is not permitted in pattern matching *)  (* Here is a binary tree datatype *) @@ -385,7 +389,7 @@ fun calculate_interest(n) = if n < 0.0  (* Exceptions can be caught using "handle" *)  val balance = calculate_interest ~180.0 -              handle Domain => ~180.0    (* x now has the value ~180.0 *) +              handle Domain => ~180.0    (* balance now has the value ~180.0 *)  (* Some exceptions carry extra information with them *)  (* Here are some examples of built-in exceptions *) @@ -395,7 +399,7 @@ fun failing_function []    = raise Empty  (* used for empty lists *)    | failing_function xs    = raise Fail "This list is too long!"  (* We can pattern match in 'handle' to make sure -   a specfic exception was raised, or grab the message *) +   a specific exception was raised, or grab the message *)  val err_msg = failing_function [1,2] handle Fail _ => "Fail was raised"                                            | Domain => "Domain was raised"                                            | Empty  => "Empty was raised" | 
