Records in Haskell

Nicolas Frisby nicolas.frisby at gmail.com
Tue Jan 3 17:37:03 CET 2012


Disclaimer: this use case for type-level string ops is still
hypothetical, so these are predictions.

Shooting for the moon, I foresee writing a type-level string
similarity metric. In my experience, that would involve nested
traversals, sliding of sequence windows, etc. In that case, I would
very much like to write the similarity measure algorithm as if the
labels were a sequence of characters. The kind in the following
signature assumes promoted lists and — though I know it's still up in
the air — some sort of promotion of characters as Char.

>  type LabelToLetters :: Label -> [Char]

Alternatively, the Char kind could simply be Label with an
extralingual invariant that it has one "character" in it — though that
doesn't smell like Haskell. The resulting kind of LabelToLetters in
this case would be (Label -> [Label]).

A class of "dumber" algorithms for "comparing" type-level promotions
of constructor names might simply attach some prefix or suffix and
then test for equality. In that case, I'd just need append.

>  type LabelAppend :: Label -> Label -> Label

I personally lean towards LabelToLetters, since I predict that any
direct interface for labels-as-sequences is going to perpetually be a
subset of whatever becomes established as the interface for type-level
lists. The symmetric LettersToLabel would be nice for balance, but I
don't foresee needing it in this use case, since comparing Labels is
more so a consumer of Labels as opposed to a producer.

Whatever the interface to Labels, I would need to be able to test
type-level characters for equality. While built-in decidable type
equality family that returns a type of kind Bool would be fantastic
(or preferably GHC ticket 1894), I'm not anticipating that anytime
soon. In order to continue using my own library for such a type-level
type equality predicate, I need to be able to provide type family
instances for the type-level characters.

>  I need type-level characters to be valid as indices in type family instances.

That's all I foresee. Thanks.

On Tue, Jan 3, 2012 at 3:32 AM, Simon Peyton-Jones
<simonpj at microsoft.com> wrote:
> | In regard to Labels versus Atom, etc., in my use case of converting
> | between similar datatypes, it would be very reasonable to eventually
> | add/remove prefixes/suffixes from these type-level reifications of
> | constructor names. If type-level strings are not implemented as lists
> | of characters, I would still like access to a comparable API.
>
> Can you be specific?  What operations, exactly, do you want?
>
> Simon
>



More information about the Glasgow-haskell-users mailing list