Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to parse a string literal #6

Closed
lambdakris opened this issue Jul 21, 2017 · 3 comments
Closed

How to parse a string literal #6

lambdakris opened this issue Jul 21, 2017 · 3 comments

Comments

@lambdakris
Copy link

Description

Referring to Parsing Routes in the docs, I was not able to parse a string literal.

Repro code

open Elmish.Browser.UrlParser

parse (s "blog") "blog"

Expected and actual result

I figured it would compile and yield Some "blog", however, the expression doesn't compile due to the following error:

Type mismatch. Expecting a 
  'Parser<('a -> 'a)>, 'a>'
but given a
  'Parser<('a -> 'a), ('a -> 'a)>'
the types ''a' and ''a -> 'a' cannot be unified

Related information

  • fable-elmish version: 0.9.2
  • fable-compiler version: 1.1.9
  • fable-core version: 1.1.7
  • Operating system: Windows 10
@et1975
Copy link
Member

et1975 commented Jul 21, 2017

s "blog" in your example refers to a "static" portion - something that is expected to be present in the input, but is not captured, ie the parser as specified has no instructions to extract something and I guess the compiler can't infer the types involved.
parse str "blog" would do what you expect it to do.

@lambdakris
Copy link
Author

I was actually looking into how to get something like the following:

type Route = Home | Search of string
let routes = 
    [ map Home (s "home")
      map Search (s "search" </> str) ]
parse (oneOf routes)

or just

parse (map Home (s "home"))

Which works, but I was just hoping there was a way to build a "match a string" expression without applying the map function...

@et1975
Copy link
Member

et1975 commented Jul 21, 2017

The idea of this parser-combinator module is that a single type unifies the parsed out values, what you are asking for can only be represented by a DU, so you need to pass the map function to construct it.

@et1975 et1975 closed this as completed Jul 21, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants