[Haskell-cafe] singToList

Dmitry Olshansky olshanskydr at gmail.com
Sun Dec 31 16:09:26 UTC 2017


I have to say that a question about types from singletons package. I am
sorry that didn't say it before.

31 дек. 2017 г. 4:05 PM пользователь "Ramin Honary" <ramin.honary at gmail.com>
написал:

> I think the closest thing I can think of that describes a "thingToList"
> kind of thing you are talking about would be the "Foldable" and
> "Traversable" class:
>
> https://hackage.haskell.org/package/base-4.10.1.0/docs/Data-Foldable.html
> https://hackage.haskell.org/package/base-4.10.1.0/docs/
> Data-Traversable.html
>
> However it is not exactly as you described, there is no direct conversion
> of a "Thing" data structure to an actual list data structure.
>
> The problem with converting data structures like Trees into lists
> structures is that this can be inefficient. Instead, think of the reason
> you want to have a list object: because you want to perform scan through
> the list to find an element, or you want to perform a fold, yes?
>
> So instead of converting to a list and then applying a fold or map
> function, it is much better to pass a mapping function to a higher-order
> function like "mapM," or "sequence," or pass a folding function a
> higher-order function like "foldM", and allow these higher-order functions
> scan through the data structure without converting it to a list first.
>
>
>
> On Sun, Dec 31, 2017 at 4:08 AM, Dmitry Olshansky <olshanskydr at gmail.com>
> wrote:
>
>> Hello cafe,
>>
>> Does a function like `singToList` exist somewhere:
>>
>> singToList :: Sing (xs :: [k]) -> [SomeSing k]
>> singToList = \case
>>   SNil -> []
>>   SCons x xs -> SomeSing x : singToList xs
>>
>> ?
>>
>> _______________________________________________
>> Haskell-Cafe mailing list
>> To (un)subscribe, modify options or view archives go to:
>> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
>> Only members subscribed via the mailman list are allowed to post.
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20171231/6c281f62/attachment.html>


More information about the Haskell-Cafe mailing list