[Haskell-cafe] What does "1 = 2" mean in Haskell?
harendra.kumar at gmail.com
Fri Feb 24 05:27:29 UTC 2017
Pattern match in a function definition is different. Here the pattern match
is actually being used as part of the function definition. We were trying
to figure out the usefulness of non-function pattern matches which do not
result in a binding. The assert case pointed out by Brandon is one example.
Though not so useful.
On 24 February 2017 at 10:30, Taeer Bar-Yam <taeer at necsi.edu> wrote:
> Since nobody has provided an example use case, I will. It's not
> particularly useful, but it's a minimal case that does something
> func :: (Int, a) -> Maybe a
> func (0, x) = Just x
> func _ = Nothing
> Excerpts from Brandon Allbery's message of February 23, 2017 10:51 pm:
>> Without a binding it is useless at top level, but if you strictify the
>> pattern it can be useful in `let` (possibly as a sanity check where you
>> want the program to abort if it fails). I don't recall offhand if it
>> desugars usefully in list comprehensions, but if so it would work as a
>> filter. There may also be other specialized use cases; general syntax
>> to get reused a lot in Haskell, so making this case a syntax error could
>> make it difficult to support actually useful cases. :)
>> (Also I'm sure someone overly clever could figure out some way to abuse
>> On Thu, Feb 23, 2017 at 10:41 PM, Harendra Kumar <
>> harendra.kumar at gmail.com>
>> On 24 February 2017 at 08:45, Brandon Allbery <allbery.b at gmail.com>
>>> Literally the only use I've seen for this was a CCC puzzle. However, it
>>>> is the trivial case of something that is more useful: pattern matching
>>>> result of an expression (say, a Data.Map.lookup when you know the key
>>> Can you explain how that will be useful (without a binding)? Will the
>>> pattern match be ever actually tried when there is no binding?
>> brandon s allbery kf8nh sine nomine
>> allbery.b at gmail.com
>> ballbery at sinenomine.net
>> unix, openafs, kerberos, infrastructure, xmonad
>> Haskell-Cafe mailing list
>> To (un)subscribe, modify options or view archives go to:
>> Only members subscribed via the mailman list are allowed to post.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Haskell-Cafe