Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert a Haskell Traversable into a Vector?

If I have a Traversable instance, xs, how do I convert it into a Vector?

like image 333
Ana Avatar asked Apr 25 '15 01:04

Ana


1 Answers

All Traversable instances are also Foldable, so you can write something like

toVector :: Foldable t => t a -> Vector a
toVector = Vector.fromList . Foldable.toList
{-# INLINE toVector #-}

This might make an intermediate list though, if that doesn't get fused away. The inlining should help make fusion more likely.

like image 179
David Young Avatar answered Nov 07 '22 07:11

David Young