Created
October 20, 2013 07:29
-
-
Save naiquevin/7066030 to your computer and use it in GitHub Desktop.
ML function patterns
This file contains 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
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 | |
*) |
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
This is a thin layer of sugar for something like (I am using F# syntax here):
The point is pattern matching is pretty much orthogonal to currying. The two features do not interact in any significant ways.