[Haskell-cafe] Implicit newtype unwrapping

Joachim Breitner mail at joachim-breitner.de
Thu Dec 3 05:07:51 EST 2009


Am Donnerstag, den 03.12.2009, 01:16 +0100 schrieb Martijn van
> 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.


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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: Dies ist ein digital signierter Nachrichtenteil
Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20091203/92f05b6e/attachment.bin

More information about the Haskell-Cafe mailing list