Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert an array to a list in PureScript

XY problem

How do I convert an array to a list in PureScript?

arrayToList :: forall a. Array a -> List a
arrayToList = ???

Actual problem

Must I necessarily write this function?

Neither purescript-arrays nor purescript-lists define such a function, which leads me wonder if there is an idiomatic way to deal with arrays in the contexts of functions taking a list.

For example Matrix.getRow returns an array which needs to be transformed into a list of Pux Html elements (in the process of rendering the matrix as HTML). What is the best way to do this?

like image 961
Sridhar Ratnakumar Avatar asked Nov 09 '16 13:11

Sridhar Ratnakumar


1 Answers

With compiler version 0.10.2, you can simply write

arrayToList :: forall a. Array a -> List a
arrayToList = ?whatGoesHere

and the compiler will give you a list of things to fill in, based on the type information. ?whatGoesHere is called a typed hole.

In this case, you probably want Data.Array.toUnfoldable or Data.List.fromFoldable.

like image 71
Phil Freeman Avatar answered Oct 18 '22 03:10

Phil Freeman