Created
January 31, 2013 11:10
-
-
Save psibi/4682181 to your computer and use it in GitHub Desktop.
Pattern Matching Records in SML
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(* Pattern Matching in Records | |
Let us pattern match {first:string,second:string,third:string} | |
*) | |
(*You should not code like this. | |
This code will produce a type of val test = fn : {a:'a, b:'b, c:'c} -> {first:'a, second:'b, third:'c} | |
So, it creates actually records with fields of a, b and c. This is not what you want. | |
*) | |
fun test e = | |
case e of | |
{a,b,c} => {first=a,second=b,third=c} | |
(*Instead you should code like this*) | |
fun test1 e = | |
case e of | |
{first=a,second=b,third=c} => {first=a,second=b,third=c} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks,it's helpful :)