[Haskell-cafe] Implicit newtype unwrapping

Sjoerd Visscher sjoerd at w3future.com
Thu Dec 3 05:25:36 EST 2009


Hmm, as long as you provide a type signature, Haskell could do implicit wrapping as well.

If I'm not mistaken, the compiler should be able to figure out what to do in this case:
> myfoo :: (Blubb -> MyFoo) -> MyFoo -> MyFoo -> MyFoo 
> myfoo = foo


Sjoerd

On Dec 3, 2009, at 11:07 AM, Joachim Breitner wrote:

> Hi,
> 
> Am Donnerstag, den 03.12.2009, 01:16 +0100 schrieb Martijn van
> Steenbergen:
>> So here's a totally wild idea Sjoerd and I came up with.
>> 
>> What if newtypes were unwrapped implicitly?
>> 
>> What advantages and disadvantages would it have?
>> In what cases would this lead to ambiguous code?
> 
> not sure if this is what you are thinking at, but everytime I wrap a
> type Foo in a newtype MyFoo to define my own instances (or just for more
> expressiveness code), I wish I had a way to tell the compiler:
> „Please define function myfoo to be the same as foo, with all occurences
> of Foo in its type signature replaced by MyFoo.“
> 
> Instead I find my self writing manually code like
> 
> myfoo :: (Blubb -> MyFoo) -> MyFoo -> MyFoo -> MyFoo 
> myfoo f (MyFoo a) (MyFoo b) = MyFoo (foo (unMyFoo . f) a b)
> 
> I guess TH could probably do this.
> 
> Greetings,
> Joachim
> 
> 
> -- 
> Joachim "nomeata" Breitner
>  mail: mail at joachim-breitner.de | ICQ# 74513189 | GPG-Key: 4743206C
>  JID: nomeata at joachim-breitner.de | http://www.joachim-breitner.de/
>  Debian Developer: nomeata at debian.org
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe

--
Sjoerd Visscher
sjoerd at w3future.com





More information about the Haskell-Cafe mailing list