Question: eeh, ok. How do I write unicode escape sequences in elm? I tried "\uXXXX" but I just get strange syntax errors

Asked By
Asked At
2018-03-18 15:11:32

Found 15 possible answers.

User Answered At Possible Answer
ilias 2018-03-18 15:14:50 The current syntax is a little funny, using \xXXXX for hexadecimal escapes. The issue is ambiguity of where the escape "ends". In the new parser, this will be a much more comprehensible \u{XXXX} syntax, though. Which character are you trying to "type"? It's quite possible you don't even need an escape sequence.
herrasbe 2018-03-18 15:16:19 it's a icon font, so I think they are in the "undefined" areas of the unicode standard IIRC
jason.o 2018-03-18 15:28:26 Hi, I’m delighted to see that multiline regex is coming in 0.19 ( ) Then I wonder if it’s possible to use the new regex module by cloning it by itself.
ilias 2018-03-18 15:29:04 @jason.o not really, the next-gen regex module uses the new format for kernel code so it's not backwards compatible @herrasbe ah, right. In that case, yeah, that's usually something like "\xXXXX"
jason.o 2018-03-18 15:30:19 ahhh…ok. thanks.
ilias 2018-03-18 15:31:07 Depending on what you're trying to do, it _may_ be nicer to use elm-tools/parser , but that would really depends on the specifics :slightly_smiling_face:
herrasbe 2018-03-18 15:33:30 Thank you @ilias , worked beautifully
tony_bradley 2018-03-18 16:30:34 I guess I'm not using extensible records correctly? ^ will tell me Cannot find variable Quest
        (  [ "description" ] Json.Decode.string)
        (  [ "name" ] Json.Decode.string)
        (  [ "id" ] Json.Decode.string)
    Json.Decode.map4 Quest
decodeQuest =
    QuestDetails { id : String }
type alias Quest =
        , description : String
        | name : String
    { a
type alias QuestDetails a =
ilias 2018-03-18 16:44:16 Yeah, you don't get the auto-generated constructor functions for extensible records. I'd recommend using a full record definition for Quest - if you have functions that only need name and description you can still use that QuestDetails type alias, though.
tony_bradley 2018-03-18 16:46:48 Interesting. I didn't know type aliases even had auto-generated constructors like those union types. But now that I think about it I _was_ just passing it to a function :stuck_out_tongue:
arup_r 2018-03-18 16:47:27 How can I covert an Float to Int ?
2 : Float
> sqrt 4
how the left and right arguments interact.
fine, I assume it is correct and check the right side. So the problem may be in
Hint: With operators like (<<) I always check the left side first. If it seems
Hint: It looks like a function needs 1 more argument.
But the right side is:
    a -> Int
(<<) is expecting the right side to be a:
3|          isEven << (sqrt 4)
The right side of (<<) is causing a type mismatch.
-- TYPE MISMATCH --------------------------------------------- repl-temp-000.elm
> not << isEven << (sqrt 4)
 : Int -> Bool
> isEven n = n % 2 == 0
ilias 2018-03-18 16:48:14 round , ceiling , floor and truncate are all options, depending on how you want to handle thins also, you're not composing a function, but rather applying one after the other so not <| isEven <| round <| sqrt 4 would do the trick
arup_r 2018-03-18 16:51:41 I took the example from doc, :slightly_smiling_face: I was just trying it to see how it works.
ilias 2018-03-18 16:55:54 right. So you _could_ write an isEven : Float -> Bool function, and then not << isEven << sqrt would give you a function. To use it, you would have something is rootIsOdd = not << isEven << sqrt so you could do rootIsOdd 25 . Or, inline, (not << isEven << sqrt) 25
arup_r 2018-03-18 16:57:31 ok :slightly_smiling_face: omg.. I got stuck in error loop

and `round` to do specific conversions.
Hint: Elm does not automatically convert between Ints and Floats. Use `toFloat`
But the left argument is:
(%) is expecting the left argument to be a:
4|             toFloat n) % 2
The left argument of (%) is causing a type mismatch.
-- TYPE MISMATCH --------------------------------------------- repl-temp-000.elm
> isEven n = (toFloat n) % 2 == 0 How shall I write this isEven : Float -> Bool ?

Related Questions