[Haskell-cafe] Implicit newtype unwrapping

Greg Fitzgerald garious at gmail.com
Thu Dec 3 14:52:37 EST 2009

On Thu, Dec 3, 2009 at 5:34 AM, Conor McBride wrote:
>  http://www.haskell.org/pipermail/libraries/2008-January/008917.html

On Tue, Jan 15, 2008 at 3:31 PM, Conor McBride wrote:
> Haskell's classes are the best damn rhythm section in
> the industry: you hum it, they play it.

On Fri, Dec 10, 2004 at 2:21 AM, Conor McBride wrote:
> If you're willing to make the types distinguish the idioms you're using,
> as in choice-lists and vector-lists, then a lot of routine operations wither
> to a huddle of combinators sitting under a type signature which actually does
> most of the work. Instance inference is like having a great rhythm section:
> you hum it, they play it.

Very eloquent Conor.  Can we get this guy quoted in HWN?  I think he's
earned it.  :-)

On Thu, Dec 3, 2009 at 5:34 AM, Conor McBride wrote:
> class Newtype n where
>  type Unpack n
>  pack :: Unpack n -> n
>  unpack :: n -> Unpack n

Nice.  Would the code below be a good way to deal with subtyping?
It'd be convenient to have some way to go from a 64-bit Double to a
32-bit Float and be informed when a Double can't be represented
precisely by a Float, but to have the option to move forward with the
minor loss of precision.

class Subset n where
  type Superset n
  demote :: Superset n -> Either n n
  promote :: n -> Superset n

squeeze :: Subset n => Superset n -> n
squeeze = either id id . demote

In action:


More information about the Haskell-Cafe mailing list