| From | Sent On | Attachments |
|---|---|---|
| Simon Peyton-Jones | Jan 14, 2013 10:09 am | |
| Stephen Paul Weber | Jan 14, 2013 10:29 am | |
| Edward Kmett | Jan 14, 2013 10:38 am | |
| Herbert Valerio Riedel | Jan 14, 2013 10:54 am | |
| Roman Cheplyaka | Jan 14, 2013 11:03 am | |
| Andrea Vezzosi | Jan 14, 2013 11:14 am | |
| Johan Tibell | Jan 14, 2013 11:41 am | |
| Stephen Paul Weber | Jan 14, 2013 11:47 am | |
| Mikhail Glushenkov | Jan 14, 2013 11:48 am | |
| Gershom Bazerman | Jan 14, 2013 11:53 am | |
| Simon Peyton-Jones | Jan 14, 2013 1:09 pm | |
| Simon Peyton-Jones | Jan 14, 2013 1:18 pm | |
| Johan Tibell | Jan 14, 2013 1:32 pm | |
| Roman Cheplyaka | Jan 14, 2013 1:45 pm | |
| Johan Tibell | Jan 14, 2013 2:29 pm | |
| Roman Cheplyaka | Jan 14, 2013 2:32 pm | |
| Edward Kmett | Jan 14, 2013 2:40 pm | |
| Johan Tibell | Jan 14, 2013 2:55 pm | |
| Roman Cheplyaka | Jan 14, 2013 2:57 pm | |
| Johan Tibell | Jan 14, 2013 3:11 pm | |
| Evan Laforge | Jan 14, 2013 3:17 pm | |
| Edward Kmett | Jan 14, 2013 3:18 pm | |
| Johan Tibell | Jan 14, 2013 3:27 pm | |
| Roman Cheplyaka | Jan 14, 2013 3:28 pm | |
| Evan Laforge | Jan 14, 2013 3:40 pm | |
| Johan Tibell | Jan 14, 2013 3:42 pm | |
| Ian Lynagh | Jan 14, 2013 3:42 pm | |
| Brandon Allbery | Jan 14, 2013 3:43 pm | |
| Ian Lynagh | Jan 14, 2013 3:46 pm | |
| Edward Kmett | Jan 14, 2013 3:48 pm | |
| Chris Dornan | Jan 14, 2013 4:20 pm | |
| Iavor Diatchki | Jan 14, 2013 6:15 pm | |
| Gábor Lehel | Jan 15, 2013 12:48 am | |
| Simon Peyton-Jones | Jan 15, 2013 12:58 am | |
| Joachim Breitner | Jan 15, 2013 1:03 am | |
| Krzysztof Gogolewski | Jan 15, 2013 6:19 am | |
| wren ng thornton | Jan 20, 2013 8:13 pm | |
| wren ng thornton | Jan 20, 2013 8:32 pm | |
| wren ng thornton | Jan 20, 2013 8:36 pm | |
| Shachaf Ben-Kiki | Jan 20, 2013 10:39 pm | |
| wren ng thornton | Jan 21, 2013 10:41 pm | |
| Gábor Lehel | Jan 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.
Krzysztof Gogolewski
_______________________________________________ Glasgow-haskell-users mailing list Glas...@haskell.org http://www.haskell.org/mailman/listinfo/glasgow-haskell-users





