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

Vlatko Basic vlatko.basic at gmail.com
Tue Oct 21 09:18:00 UTC 2014


Hi Erik,

Thanks for the tip.


Interestingly, on Reddit [1] just appeared almost the same problem with some 
suggestions.


vlatko


[1] - 
http://www.reddit.com/r/haskell/comments/2jsz4t/function_on_a_single_member_of_a_sum_type/

-------- Original Message  --------
Subject: Re: [Haskell-cafe] Limit elements of a list to a certain value
From: Erik Hesselink <hesselink at gmail.com>
To: Vlatko Bašić <vlatko.basic at gmail.com>
Cc: haskell <Haskell-cafe at haskell.org>
Date: 20.10.2014 11:55

> 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