[Haskell-cafe] Current research on overlapping/closed type families?

Simon Peyton-Jones simonpj at microsoft.com
Thu Jan 29 13:07:59 EST 2009


| Would this then also eventually work?
|
| data Zero = Zero
| data Succ a = Succ a
|
| type family IsFunction f
|
| type instances
|    IsFunction (a -> b) = Succ (IsFunction b)
|    IsFunction c        = Zero

It's delicate. Consider

        f :: a -> IsFunction a
        f x = Zero

        h = f ord

The defn of f looks ok, but if you were to inline it at the call site, where it's applied to 'ord', which has a functional type, you'll see that 'a' is instantiated by (Char -> Int)...

A similar issue arises with type classes and overlapping instances.  Generally GHC refrains from committing to an instance declaration until it's clear that no other instance can match (in which case the above defn would be rejected).  Maybe the same thing will work for equalities; I have not thought about it.

Simon


|
|
| Simon Peyton-Jones wrote:
| > Provided all the overlapping instances are supplied together, as you
| suggest, I think what you say makes perfect sense and does not threaten
| soundness.
| >
| > But we have not yet implemented the idea yet.  First priority is to
| get type families working properly, and in conjunction with type
| classes.  Then we can move on to adding features.
| >
| > Simon
| >
| > | -----Original Message-----
| > | From: haskell-cafe-bounces at haskell.org [mailto:haskell-cafe-
| > | bounces at haskell.org] On Behalf Of Ryan Ingram
| > | Sent: 19 January 2009 23:24
| > | To: Haskell Cafe
| > | Subject: [Haskell-cafe] Current research on overlapping/closed type
| families?
| > |
| > | What's the status of overlapping/closed type families?  I'm
| interested
| > | in something like the following, which can currently be implemented
| in
| > | GHC with Oleg-magic using functional dependencies, but cannot, to
| my
| > | knowledge, be implemented with type families:
| > |
| > | data HTrue = HTrue
| > | data HFalse = HFalse
| > |
| > | type family IsFunction f
| > |
| > | {- not legal in GHC6.10 -}
| > | type instances
| > |    IsFunction (a -> b) = HTrue
| > |    IsFunction a = HFalse
| > |
| > |   -- ryan
| > | _______________________________________________
| > | Haskell-Cafe mailing list
| > | Haskell-Cafe at haskell.org
| > | http://www.haskell.org/mailman/listinfo/haskell-cafe
| >
| > _______________________________________________
| > Haskell-Cafe mailing list
| > Haskell-Cafe at haskell.org
| > http://www.haskell.org/mailman/listinfo/haskell-cafe
| >
| >
|



More information about the Haskell-Cafe mailing list