How to test run elm/url in REPL?

I’m just an Elm beginner. And now I’m trying to test elm/url in REPL, I did the following steps:

myParser = s “foo”
myUrl = { fragment = Nothing, host = “”, path = “#foo”, port_ = Nothing, protocol = Http, query = Nothing }

Now I try this in REPL:
Parser.parse myParser myUrl

And bang, I got infinite types error, no idea what I did wrong, so could anyone please give me a hint? Thank you.

The following steps works in elm repl:

import Url
import Url.Parser as Parser
myParser = "GotFoo" (Parser.s "foo")
myUrl = { fragment = Nothing, host = "", path = "/foo", port_ = Nothing, protocol = Url.Http, query = Nothing }
Parser.parse myParser myUrl

Your myParser = s "foo" is of type Parser a a when parse requires first parameter to be of type Parser (a -> a) a. Basically you need a parser which returns something from successful parse.

For example you can use myParser = "GotFoo" (Parser.s "foo") which maps return value you want to actual parser. I used a String value "GotFoo" here to make example simple but usually you would use some custom type instead.

Parser like myParser = Parser.s "foo" </> will also work as it has return value. This one parses a path like /foo/123 and then returns that 123.

ps. "#foo" is not valid path, so I fixed that to "/foo" in your example.

Hi malaire, thank you so much, now I understand why my code is not working.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.