Skip to content

Instantly share code, notes, and snippets.

@naiquevin
Created October 20, 2013 07:29
Show Gist options
  • Save naiquevin/7066030 to your computer and use it in GitHub Desktop.
Save naiquevin/7066030 to your computer and use it in GitHub Desktop.
ML function patterns
fun xyz 1 = "single"
| xyz 2 = "double"
| xyz 3 = "triple"
| xyz _ = "multiple"
(*
val xyz = fn : int -> string
val it = () : unit
- xyz 1;
val it = "single" : string
- xyz 2;
val it = "double" : string
- xyz 3;
val it = "triple" : string
- xyz 4;
val it = "multiple" : string
*)
@missingfaktor
Copy link

This is a thin layer of sugar for something like (I am using F# syntax here):

let xyz n = match n with
  | 1 -> "single"
  | 2 -> "double"
  | 3 -> "triple"
  | _ -> "multiple"

The point is pattern matching is pretty much orthogonal to currying. The two features do not interact in any significant ways.

@naiquevin
Copy link
Author

My point was that the reason we can get away with ML functions taking only single arg is that it can create "args" (precisely, local bindings) from a tuple pattern to make it feel like any other language that supports multiple args. Well, this sounds more like destructuring and not pattern matching so I think I get your point now.

Anyway, from the twitter conversation with you and @dnene (specially "the value is to caller.. function def isn't impacted" part) it seems I am missing something deep that's currently out of the scope of my understanding. Hopefully it will be clear as the course progresses. Thanks for starting this conversation.

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