Allow symbols in data contructors#2384
Conversation
examples/passing/DctorName.purs
Outdated
|
|
||
| data Baz'' = Baz'' | ||
|
|
||
| main = log "Done" |
There was a problem hiding this comment.
Could you please add an example where you case on one of these new constructors? Thanks.
There was a problem hiding this comment.
Thanks, this has caught the case where the parser for the constructor binding in case statements did not deal with the symbols. I have updated the parser and example.
| return $ JSApp Nothing (JSFunction Nothing Nothing [] (JSBlock Nothing (ds' ++ [JSReturn Nothing ret]))) [] | ||
| valueToJs' (Constructor (_, _, _, Just IsNewtype) _ (ProperName ctor) _) = | ||
| return $ JSVariableIntroduction Nothing ctor (Just $ | ||
| return $ JSVariableIntroduction Nothing (identToJs . Ident $ ctor) (Just $ |
There was a problem hiding this comment.
It's probably worth pulling this out into its own small function.
There was a problem hiding this comment.
Great, I have created a function for this
|
Looks great so far, thanks! |
| properToJs :: String -> String | ||
| properToJs name | ||
| | nameIsJsReserved name || nameIsJsBuiltIn name = "$$" ++ name | ||
| | otherwise = concatMap identCharToString name |
There was a problem hiding this comment.
Might be worth refactoring identToJs to use this in the (Ident name) case - as the implementation is the same.
examples/passing/DctorName.purs
Outdated
| g Baz'' = 0 | ||
| g Baz' = 1 | ||
|
|
||
| h :: Bar' -> Int |
There was a problem hiding this comment.
Could you please make sure these cases actually get run? You could do this by adding additional top-level declarations of type Int for example, where you apply each function.
There was a problem hiding this comment.
Thanks for the feedback. Would this do ?
f' ∷ Boolean
f' = f $ Foo' $ Bar' 0
g' ∷ Int
g' = g Baz''
h' ∷ Int
h' = h $ Bar' 4
|
Thanks! |
I would like to attempt to contribute a solution to resolve #2208
As I am new to the Purescript compiler, I am not sure if there is anything that I have overlooked here or if there is perhaps a better way to achieve this.
In essence, the changes I have made are: