[Haskell-cafe] Limit elements of a list to a certain value

Erik Hesselink hesselink at gmail.com
Mon Oct 20 09:55:27 UTC 2014


You could do it by making Parsed into a GADT:

data Parsed ev where
  PEvent :: Event -> Parsed E1
  ...

As for the question about promoting 'Q', I think it's because it
contains a String, and the Symbol kind doesn't map one-to-one to
String, since it's opaque. The same goes for types containing
Integers, I guess. They also cannot be promoted, as Integer doesn't
map cleanly to Nat. I'm just guessing here, though.

Erik

On Mon, Oct 20, 2014 at 11:02 AM, Vlatko Basic <vlatko.basic at gmail.com> wrote:
> Hello Cafe,
>
> I have these datatypes
>
> data Event = E1 {...} | E2 {...} | E3 {...}
> data Parsed = PEvent Event | PLine Text | PHeader Text
>
> I'd like to split the list of Parsed values into separate lists with a
> guaranty
> that each of those lists contains only the elements of the same type, as in
> [PEvent E1] [PEvent E2] [PLine Text] ...
>
>
> How can that be achieved on type level (without creating newtypes for each
> case)?
> I tried with type families, but failed.
>
> Also, an explanation of why the Event above (or "data Q = Q1 | Q2 String")
> is not promotable to kind level would be welcome.
>
>
> best regards,
>
> vlatko
> _______________________________________________
> 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