[Haskell-cafe] checking types with type families
quick at sparq.org
Sat Jul 3 21:59:35 EDT 2010
On Sat, 03 Jul 2010 13:28:44 -0700, Dan Doel <dan.doel at gmail.com> wrote:
>> As a side note, although I agree it abuses the fundeps intent, it was handy
>> for the specific purpose I was implementing to have a "no-op/passthrough"
>> instance of op. In general I like the typedef approach better, but it
^^^^^^^ should have been "type family", not "typedef"
>> looks like I must sacrifice the no-op to make that switch.
>It's potentially not just a violation of intent, but of soundness.
I agree when examining this from the perspective of the compiler. It's an interesting little wormhole in the safety net usually provided by Haskell (or more properly GHC in this case) to stop people like me from doing foolish things.
From the domain of the original problem, having a no-op instance is still desireable, and I achieved this by making the noop instance type polymorphic and use the target concrete type to guide the resolution of the interior family types.
class C a where
type A2 a
type A3 a
op :: a -> A2 a -> A3 a
data NoOp x = NoOp
instance C (NoOp b) where
type A2 (NoOp x) = x
type A3 (NoOp x) = x
op _ = id
This is straightforward and less ambiguous and should therefore be safer as well.
Thanks and regards,
More information about the Haskell-Cafe