Search code examples
elm

Can't add Dictionary to Repl


How can I add this to the repl with line returns?

import Dict
fruit = Dict.fromList \
    [ \
      ((0,0), 'Apple') \
      ,((0,1), ' ') \      
    ]

Error:

> fruit = Dict.fromList \
|     [ \
|       ((0,0), 'Apple') \
|       ,((0,1), ' ') \      
-- SYNTAX PROBLEM -------------------------------------------- repl-temp-000.elm

The = operator is reserved for defining variables. Maybe you want == instead? Or
maybe you are defining a variable, but there is whitespace before it?

5|   fruit = Dict.fromList 

Is it just not possible to do this in the repl with lists where you want to add line returns?


Solution

  • Not a language I know but thought I'd take a look. This appears to work:

    import Dict
    fruit = Dict.fromList \
        [ \
          ((0,0), "Apple") \
          ,((0,1), " ") \
        ]
    

    You seem to have some trailing whitespace after ,((0,1), ' ') \

    Also I needed double quotes which appears to be supported by https://elmprogramming.com/string.html

    By way of minimal test - this behaves like your example if the trailing space is included:

    import Dict
    fruit = Dict.fromList [ \