Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you print a List in Elm?

Tags:

elm

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

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

Example

Let's say I have a function intAverage:

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

Here I want to inspect the list, in order to understand what's being passed to my function. Debug.log expects a String which makes me look for a function with the signature a -> String or List -> String but I have been unsuccessful in finding such a function in the Elm package docs.

Haskell has Debug.traceShow (which is simply an application of the function show on the first argument of Debug.trace) but I can't find the equivalent in Elm.

like image 750
qff Avatar asked Oct 30 '15 02:10

qff


1 Answers

Edit: This is no longer true as of Elm version 0.19. See the other answer to this question.

The toString was what I was looking for, but couldn't find.

toString :: a -> String

I found it in the Basics-package: toString documentation

like image 54
qff Avatar answered Sep 28 '22 08:09

qff