atom feed42 messages in org.haskell.glasgow-haskell-usersNewtype wrappers
FromSent OnAttachments
Simon Peyton-JonesJan 14, 2013 10:09 am 
Stephen Paul WeberJan 14, 2013 10:29 am 
Edward KmettJan 14, 2013 10:38 am 
Herbert Valerio RiedelJan 14, 2013 10:54 am 
Roman CheplyakaJan 14, 2013 11:03 am 
Andrea VezzosiJan 14, 2013 11:14 am 
Johan TibellJan 14, 2013 11:41 am 
Stephen Paul WeberJan 14, 2013 11:47 am 
Mikhail GlushenkovJan 14, 2013 11:48 am 
Gershom BazermanJan 14, 2013 11:53 am 
Simon Peyton-JonesJan 14, 2013 1:09 pm 
Simon Peyton-JonesJan 14, 2013 1:18 pm 
Johan TibellJan 14, 2013 1:32 pm 
Roman CheplyakaJan 14, 2013 1:45 pm 
Johan TibellJan 14, 2013 2:29 pm 
Roman CheplyakaJan 14, 2013 2:32 pm 
Edward KmettJan 14, 2013 2:40 pm 
Johan TibellJan 14, 2013 2:55 pm 
Roman CheplyakaJan 14, 2013 2:57 pm 
Johan TibellJan 14, 2013 3:11 pm 
Evan LaforgeJan 14, 2013 3:17 pm 
Edward KmettJan 14, 2013 3:18 pm 
Johan TibellJan 14, 2013 3:27 pm 
Roman CheplyakaJan 14, 2013 3:28 pm 
Evan LaforgeJan 14, 2013 3:40 pm 
Johan TibellJan 14, 2013 3:42 pm 
Ian LynaghJan 14, 2013 3:42 pm 
Brandon AllberyJan 14, 2013 3:43 pm 
Ian LynaghJan 14, 2013 3:46 pm 
Edward KmettJan 14, 2013 3:48 pm 
Chris DornanJan 14, 2013 4:20 pm 
Iavor DiatchkiJan 14, 2013 6:15 pm 
Gábor LehelJan 15, 2013 12:48 am 
Simon Peyton-JonesJan 15, 2013 12:58 am 
Joachim BreitnerJan 15, 2013 1:03 am 
Krzysztof GogolewskiJan 15, 2013 6:19 am 
wren ng thorntonJan 20, 2013 8:13 pm 
wren ng thorntonJan 20, 2013 8:32 pm 
wren ng thorntonJan 20, 2013 8:36 pm 
Shachaf Ben-KikiJan 20, 2013 10:39 pm 
wren ng thorntonJan 21, 2013 10:41 pm 
Gábor LehelJan 22, 2013 12:50 am 
Subject:Newtype wrappers
From:Krzysztof Gogolewski (krz.@gmail.com)
Date:Jan 15, 2013 6:19:28 am
List:org.haskell.glasgow-haskell-users

The idea can be extended to other situations where unsafeCoerce is justified: empty types and phantom types. Given declarations

data Void data Void' data Const a b = Const a

we can create O(1) wrappers:

f :: F Void -> F Void' -- empty datatypes are exchangeable g :: F (Const a Int) -> F (Const a Bool) -- phantom parameter is insignificant

assuming they do not mess with invariants of F.

From this perspective I prefer proposal 2 (a new constraint): new types of coercions might be added by adding special cases in the constraint solver. It is also a reuse of syntax: we can write

foo = newtypeCast :: [Int] -> [Age]

instead of adding a new form of declaration.

_____________________

As for safety, in some sense Map a b is parametric in a and b except the Ord instance of a. We can coerce Map a b into Map c d if we can coerce a into c, b into d and the Ord a instance matches Ord c instance (for example, one is derived from the other). This could be implemented via an instance like this:

instance (a ~~ c, b ~~ d, Ord a ~~ Ord c) => Map a b ~~ Map c d

where ~~ is kind-polymorphic "equality up to newtypes".

If Map was, say, indexed (nonparametric) in the first argument, that would be:

instance b ~~ d => Map a b ~~ Map a d

etc.