Open basile-henry opened 3 months ago
Type signatures are allowed, but not with a literal like "hello" or 123, this is the case for all Roc code, not just in the repl. You can do:
hello : Str
hello = "hey"
We should provide a nice error message here though. When using "hello" : Str
in a roc file you get a SYNTAX PROBLEM error. The repl should also throw/report this error
My expectation was that what the REPL prints was valid code [...]
It is convenient to know the type of your output and the : Str
is a familiar syntax to indicate this. Do you have any suggestions how we could fix/improve the expectations around this?
Ah right, I see, type annotations cannot be used as expressions like they can in Haskell where something like ("hello" :: String)
is a valid expression. I thought Elm was the same as Haskell, but it looks like it's exactly like Roc: the type annotation is not an expression but the REPL makes it look like it could be :sweat_smile:
Do you have any suggestions how we could fix/improve the expectations around this?
I guess if it didn't panic and gave an error message I would understand that type annotations aren't expressions in Roc (and I don't need them to be).
For reference here is what Elm gives me:
---- Elm 0.19.1 ----------------------------------------------------------------
Say :help for help and :exit to exit! More at <https://elm-lang.org/0.19.1/repl>
--------------------------------------------------------------------------------
> "Hello"
"Hello" : String
> "Hello" : String
|
-- UNEXPECTED SYMBOL ------------------------------------------------------ REPL
I was not expecting to run into the "has type" symbol here:
3| "Hello" : String
^
Maybe you want :: instead? To put something on the front of a list?
Note: The single colon is reserved for type annotations and record types, but I
think I am parsing the definition of `repl_input_value_` right now.
Note: I may be getting confused by your indentation. Is this supposed to be part
of a type annotation AFTER the `repl_input_value_` definition? If so, the
problem may be a bit before the "has type" symbol. I need all definitions to be
exactly aligned (with exactly the same indentation) so the problem may be that
this new definition is indented a bit too much.
This was on https://www.roc-lang.org/#try-roc but I get a similar error in the CLI REPL
My expectation was that what the REPL prints was valid code, so I thought a type signature/annotation would be allowed. Is that not the case?