[Haskell-cafe] Re: Combining Wouter's expressions with extensible records

Ron Alford ronwalf at volus.net
Thu Jul 10 18:38:47 EDT 2008


Close - it compiles now!  I made a minor change, going to Typeable1
instead of Typeable:

instance (Typeable1 f, Typeable1 g) => Typeable1 (f :+: g) where
    typeOf1 l@(Inl x) = mkTyConApp (mkTyCon "Planning.Wouter.:+:")
[typeOf1 x, typeOf1 y]
        where (Inr y) = undefined `asTypeOf` l
    typeOf1 r@(Inr y) = mkTyConApp (mkTyCon "Planning.Wouter.:+:")
[typeOf1 x, typeOf1 y]
        where (Inl x) = undefined `asTypeOf` r

Except this gives me a runtime error:
*WouterTest> getName testNamed
"*** Exception: Prelude.undefined

The only thing I can think of is to have a class that gives default
values to type - ick!

-Ron Alford

On Thu, Jul 10, 2008 at 4:16 PM, Antoine Latter <aslatter at gmail.com> wrote:
> On Thu, Jul 10, 2008 at 2:15 PM, Ron Alford <ronwalf at volus.net> wrote:
>> I'm making progress, but how would I make the following a Typeable instance:
>> data (f :+: g) e = Inl (f e) | Inr (g e) deriving Eq
>>
>> Here is what I'm using for Expr:
>> data Expr f = In (f (Expr f))
>> instance Typeable1 f => Typeable (Expr f) where
>>    typeOf (In x) = mkTyConApp (mkTyCon "Data.Trie.General.ListGT") [typeOf1 x]
>>
>> I don't think I can use this for ':+:', because the typeOf instance
>> only has access to a member of one type at a time.
>> This may be similar to a definition of Typeable2 for Either, but I
>> can't find an example to follow for that.
>>
>
> Maybe something like:
>
> instance (Typeable1 f, Typeable1 g) => Typeable (f :+: g) where
>  typeOf in@(InL f) = (some function of 'f' and 'g')
>                where  InR g = undefined `asTypeOf` in
>
>  typeOf in@(InR g) = (some function of 'f' and 'g')
>                where InL f = undefined `asTypeOf` in
>
> would work?
>
> -Antoine
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: WouterTest.hs
Type: application/octet-stream
Size: 5429 bytes
Desc: not available
Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20080710/85cc3618/WouterTest-0001.obj


More information about the Haskell-Cafe mailing list