How do you print List in Elm?

How to convert a value of type List to String in Elm?

Basically I am looking for a function with the signature a -> String or List -> String .

Example

Say I have an intAverage function:

 intAverage l = case l of [] -> 0 otherwise -> Debug.log (<<SHOW_FUNCTION>> l) (List.sum l // List.length l) 

Here I want to check the list to understand what is being passed to my function. Debug.log expects a String force me to look for a function with a signature a -> String or List -> String , but I could not find such a function in the Elm package documents.

Haskell has a Debug.traceShow (it's just a show function application by the first argument of Debug.trace ), but I cannot find the equivalent in Elm.

+9
elm
source share
2 answers

toString was what I was looking for but could not find.

 toString :: a -> String 

I found it in the package Basics: toowring docoumentation

+8
source share

On Elm 0.19, it was moved to Debug.toString :

For example:

 > Debug.toString [1,2,3] "[1,2,3]" : String 
0
source share

All Articles