Eta-reducing case branches

Has anyone ever considered permitting case branches to be eta reduced? For example, it is often nice to rewrite foo x = bar baz x as foo = bar baz Likewise, I have often wanted to rewrite case m of Nothing -> n Just x -> quux x as case m of Nothing -> n Just -> quux Am I missing an obvious reason this wouldn't work? Tom

Tom Ellis
Has anyone ever considered permitting case branches to be eta reduced? For example, it is often nice to rewrite
foo x = bar baz x
as
foo = bar baz
Likewise, I have often wanted to rewrite
case m of Nothing -> n Just x -> quux x
as case m of Nothing -> n Just -> quux
Am I missing an obvious reason this wouldn't work?
Tom
I would think that is a bit weird since Nothing and Just have different types. -- - Frank

Well, I think his proposal was that for a constructor C with n slots, the
RHS of the case alt would be expected to be an n-ary function where arg*i*
for *i..n* would have type T*i* for the types of each slot in C. I think it
adds up logically... but it is rather odd.
On 10 April 2015 at 20:35, Frank Staals
Tom Ellis
writes: Has anyone ever considered permitting case branches to be eta reduced? For example, it is often nice to rewrite
foo x = bar baz x
as
foo = bar baz
Likewise, I have often wanted to rewrite
case m of Nothing -> n Just x -> quux x
as case m of Nothing -> n Just -> quux
Am I missing an obvious reason this wouldn't work?
Tom
I would think that is a bit weird since Nothing and Just have different types.
--
- Frank _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe

Tom Ellis wrote:
Likewise, I have often wanted to rewrite
case m of Nothing -> n Just x -> quux x
Why not emply the maybe function (b -> (a -> b) -> Maybe a -> b) maybe n quux m Erik -- ---------------------------------------------------------------------- Erik de Castro Lopo http://www.mega-nerd.com/

On Sat, Apr 11, 2015 at 01:22:22AM -0700, Erik de Castro Lopo wrote:
Tom Ellis wrote:
Likewise, I have often wanted to rewrite
case m of Nothing -> n Just x -> quux x
Why not emply the maybe function (b -> (a -> b) -> Maybe a -> b)
maybe n quux m
This is a fine idea which I often use on simple examples like this. My proposal has some additional benefits * Closer connection between the names of the constructors and the alternatives (I always think "is it `maybe n quux` or `maybe quux n`"?. In fact I made this mistake just today.) * No need to hand write such a function for each ADT you define (arguably they could be autogenerated, but that's a different story). * You could nest matches: data Foo = Foo (Maybe Int) Bool | Bar String case m of Foo (Just 1) -> f Foo Nothing -> g Bar "Hello" -> h
participants (4)
-
Christopher Done
-
Erik de Castro Lopo
-
Frank Staals
-
Tom Ellis