Skip to content

Instantly share code, notes, and snippets.

@psibi
Created January 31, 2013 11:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save psibi/4682181 to your computer and use it in GitHub Desktop.
Save psibi/4682181 to your computer and use it in GitHub Desktop.
Pattern Matching Records in SML
(* 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}
@ztreble
Copy link

ztreble commented May 1, 2021

Thanks,it's helpful :)

@ameeruljunaidi
Copy link

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment