Extracting type metadata from Elm code?

Incidentally, I did try to do just that only 2 days ago.

It would certainly be possible with an API similar to elm-codec, but coming up with an API that is similar to Url.Parser seemed very difficult.

Elm-codec is essentially similar to e.g. Json.Decoder. But Url.Parser works differently.

-- hypothetical syntax
infix <*> = D.andMap

decode : D.Decoder Person
decode =
    (D.map Person <*> D.field "name" D.string) <*> D.field "age" D.int
route : Parser (Person -> a) a
route =
     Parser.map Person (Parser.string </> Parser.int)

They both have a map, but with very different types. Both have some form of combination operator, D.andMap and </>. But you can see how the brackets associate differently.

While Json.Decode works like a basic Applicative, Url.Parser seems to have some kind of continuation-style API. I haven’t seen such an API used like that. I’d love to see more examples of it.

And yeah. I couldn’t easily build an API that feels similar to Url.Parser but achieves something like what elm-codec improves over elm/json.