oleg | 27 Feb 09:28 2013

Help to write type-level function


Dmitry Kulagin wrote:
> I try to implement typed C-like structures in my little dsl.

HList essentially had those
        http://code.haskell.org/HList/

> I was unable to implement required type function:
> type family Find (s :: Symbol) (xs :: [(Symbol,Ty)]) :: Ty
> Which just finds a type in a associative list.

HList also implemented records with named fields. Indeed, you need a
type-level lookup in an associative list, and for that you need type
equality. (The ordinary List.lookup has the Eq constraint, doesn't
it?) 

Type equality can be implemented with type functions, right now.
        http://okmij.org/ftp/Haskell/typeEQ.html#TTypeable

(That page also defined a type-level list membership function).
Dmitry Kulagin | 27 Feb 10:57 2013
Picon

Re: Help to write type-level function

That seems to be very relevant to my problem (especially HList.Record).
Am I right that UndecidableInstances is required mostly because of eq on types, like in this instances:
class HRLabelSet (ps :: [*]) instance HRLabelSet '[] instance HRLabelSet '[x] instance ( HEq l1 l2 leq , HRLabelSet' l1 l2 leq r ) => HRLabelSet (LVPair l1 v1 ': LVPair l2 v2 ': r)
so the usage of the extension is unavoidable for my purposes?

Thank you!


On Wed, Feb 27, 2013 at 12:28 PM, <oleg <at> okmij.org> wrote:

Dmitry Kulagin wrote:
> I try to implement typed C-like structures in my little dsl.

HList essentially had those
        http://code.haskell.org/HList/

> I was unable to implement required type function:
> type family Find (s :: Symbol) (xs :: [(Symbol,Ty)]) :: Ty
> Which just finds a type in a associative list.

HList also implemented records with named fields. Indeed, you need a
type-level lookup in an associative list, and for that you need type
equality. (The ordinary List.lookup has the Eq constraint, doesn't
it?)

Type equality can be implemented with type functions, right now.
        http://okmij.org/ftp/Haskell/typeEQ.html#TTypeable

(That page also defined a type-level list membership function).






_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe <at> haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Gmane