11
votes

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?

1

1 Answers

15
votes

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.