3 ms·
Yup, in Haskell it's as explicit as a <- for assignment, and = for what amounts to pattern equality.
by lsb 17y ago
Yup, in Haskell it's as explicit as a <- for assignment, and = for what amounts to pattern equality.
- lanaer 17y agoIirc, it isn’t even assignment, it’s a monad extraction. e.g. a <- [2] … gives a the value of 2, unwrapping the List monad (only works if the return value of the function is a List of some kind). The above could also be written: [2] >> (\a -> …) It’s been a while since I’ve done much with haskell, so forgive me if I’ve mis-remembered something.
- sharkbrainguy 17y agoI accidentally downvoted this...
- llimllib 17y agoI know that's what it does under the covers, but is there any reason not to think of it as assignment in your head? That's the mental construct I use in my extremely limited Haskell coding, anyway.
- lanaer 17y agoBecause if you think of it as assignment, the fact that a <- [2] binds a to 2, rather than [2], makes no sense. edit: a better example (because it is more useful) would be: a <- Just 2 which, again, binds a to 2, unwrapping the Maybe monad in the process. (I forget what happens if you try to do a <- Nothing)
- shachaf 17y agoAs lanaer said, "<-" is really syntax sugar for ">>=" (bind), and could mean a variety of things (including assignment). "=" is binding a variable, as in "let", and is not symmetric. One could argue that a better name for "=" would be "->", as in "case". (Comparison, which is symmetric, is "==".)