Hi,I also support Jon's proposal for standalone of { ... }. Seems to me clearer and more useful than the special "\case" construct.I suppose 'of { ... }' could be generalized to multiple arguments, so thatof (Just x) (Just y) -> x ++ ywould create an anonymous function of type 'Maybe String -> Maybe String -> String'.Considering the recent thread about partial functions:we could have variants of 'of' to distinguish partial functions. For example, we could have something like 'ofFull' that would require an exhaustive list of patterns, and something like 'ofPart' that would instead produce results of type 'Maybe something'. (Most likely we'd have to think of better names for them.) For example:ofPart [x] [y] -> x ++ ywould be of type '[String] -> [String] -> Maybe String', returning `Nothing` if one of the input isn't a 1-element list - an approach similar to Scala's partial functions. <http://www.scala-lang.org/api/current/scala/PartialFunction.html>[Perhaps we could have 'of' to work both ways - if the list of patterns would be exhaustive, the result would be pure. If it would be non-exhaustive, the result would be 'Maybe something'. Of course 'case x of ...' would still work as now, not caring about exhaustiveness. But I'm not sure if this wouldn't be too error prone.]We could even generalize 'ofPart' to work with any Alternative instance so thatofPart [x] [y] -> x ++ ywould be of type '(Alternative f) => [String] -> [String] -> f String'. Matching patterns would return results using 'pure', non-matching 'empty', and they would be all combined combined using <|>. 'empty' would be returned if nothing matched. (Among other things, this could have some interesting consequences when overlapping patterns would be applied to 'Alternative []'.) For examplefn = ofPart (Right 0) -> 1(Right x) -> xwould produce (using today's syntax):fn :: (Alternative f) => Either Bool Int -> f Intfn x = case x of { Right 0 -> pure 1 ; _ -> empty; } <|>case x of { Right x -> pure x ; _ -> empty; } <|>emptyBest regards,Petr2012/12/29 Tom Ellis <tom-lists-haskell-cafe-2013@jaguarpaw.co.uk>
On Thu, Nov 29, 2012 at 05:49:53PM +0000, Jon Fairbairn wrote:> > [...] should *definitely* go into Haskell'13.
> Ben Franksen <ben.franksen at online.de> writes:
> > just wanted to drop by to say how much I like the new lambda case extension.
> > I use it all the time and I just *love* how it relieves me from conjuring up
> > dummy variables, which makes teh code not only esier to write but also to
> > read.
>
[...]
> To me it seems obvious that if we are going to do this [...] we should do
> it simply by making the "case exp" part of a case expression optional.> of {alts...}
>
>> case e of {...}
> and we would then describe
>
>
> as syntactic sugar for
>
> (of {...}) (e)
My very belated and unsolicited layman's reply is that I am a strong
supporter of Jon's position. His suggestion is parsimonious and natural.
Without wishing to start the discussion again, I disagree that it is
bikeshedding. One lesson I learned from Haskell is that syntax is much more
important than I previously realised.
Tom
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe