[Haskell-cafe] singToList

Ramin Honary ramin.honary at gmail.com
Sun Dec 31 13:05:01 UTC 2017

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:


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>

> 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/9a952c03/attachment.html>

More information about the Haskell-Cafe mailing list