# Cryptic type error with Url.Parser

**URL:** <https://discourse.elm-lang.org/t/cryptic-type-error-with-url-parser/2214>\
**Category:** Learn\
**Created:** [October 14, 2018, 8:30pm UTC](https://discourse.elm-lang.org/t/cryptic-type-error-with-url-parser/2214 "2018-10-14T20:30:02Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jess\_Bromley](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/jess_bromley/32/3396_2.png) [@Jess\_Bromley](https://discourse.elm-lang.org/u/Jess_Bromley)\
**Post date:** [October 14, 2018, 8:30pm UTC](https://discourse.elm-lang.org/t/cryptic-type-error-with-url-parser/2214/1 "2018-10-14T20:30:03Z")

</div>

I’m trying to extract the _first_ element from the path of a URL using the 0.19 Url.Parser. At first I tried this:

```auto
pathHead =
    Url.fromString "https://api.keyvalue.xyz/a17766c6/myKey"
        |> Maybe.andThen (Url.Parser.parse Url.Parser.string)

```

but that gives me `Nothing`. So I reasoned that maybe I needed to tell the parser that I was expecting a second element to the path, so I tried…

```auto
pathHead =
    Url.fromString "https://api.keyvalue.xyz/a17766c6/myKey"
        |> Maybe.andThen (Url.Parser.parse (Url.Parser.string </> Url.Parser.string))

```

This fails to compile with a `Type Mismatch` but then says that the type I gave it is the same as the type it requires?? Specifically:

```auto
Type Mismatch
Line 76, Column 52
The 1st argument to `parse` is not what I expect:

76| |> Maybe.andThen (Url.Parser.parse (Url.Parser.string </> Url.Parser.string))
                                                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
This argument is:

    Url.Parser.Parser (String -> String) String

But `parse` needs the 1st argument to be:

    Url.Parser.Parser (String -> String) String

```

So…

1. What do I do to actually extract the first element of the path?

2. Is this a bug in the compiler’s error message generator?

---

<div class="post-metadata">

**Author:** ![roovo](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.elm-lang.org/roovo/32/49_2.png) [@roovo](https://discourse.elm-lang.org/u/roovo)\
**Post date:** [October 14, 2018, 9:45pm UTC](https://discourse.elm-lang.org/t/cryptic-type-error-with-url-parser/2214/2 "2018-10-14T21:45:22Z")

</div>

It’s almost there:

```elm
pathHead : Maybe String
pathHead =
    Url.fromString "https://api.keyvalue.xyz/a17766c6/myKey"
        |> Maybe.andThen (Url.Parser.parse (Url.Parser.string </> Url.Parser.s "myKey"))

```

should do the trick. Not sure how to make sense of the compilation error tho…

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex035/uploads/elm_lang/original/1X/50a05e53677a2c3b47776d7abd0f113eb50193a1.png) [@system](https://discourse.elm-lang.org/u/system)\
**Post date:** [October 24, 2018, 9:45pm UTC](https://discourse.elm-lang.org/t/cryptic-type-error-with-url-parser/2214/3 "2018-10-24T21:45:27Z")

</div>

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