See also this Ellie: https://ellie-app.com/4fMnyrx7KLra1
I am using Elm-markup (great library!) and I am studying the example in the source code. The type annotation of document is document : Mark.Document (model -> Element msg). So, the result is a view function.
So, this code works just fine:
show : Html msg
show =
case Mark.parse document content of
Ok element -> element () |> Element.layout []
Err errors -> errors |> Debug.toString |> Element.text |> Element.layout []
For my use case I will be using several types of documents. So, I thought of creating a generic show function that accepts a document of type Mark.Document (model -> Element msg). Like this:
showGeneric documentType str =
case Mark.parse documentType str of
Ok element -> element () |> Element.layout []
Err errors -> errors |> Debug.toString |> Element.text |> Element.layout []
show1 =
showGeneric document content
And this code also works just fine. However, showGeneric does not have a type annotation. So, I added:
showGeneric : Mark.Document (model -> Element msg) -> String -> Html msg
But, then the compiler throws an error:
The 1st argument to `element` is not what I expect:
51| Ok element -> element () |> Element.layout []
^^
This argument is a unit value:
()
But `element` needs the 1st argument to be:
model
I am struggling to understand what the correct type annotation for showGeneric should be or why showGeneric does work without a type annotation and not with a type annotation.
Can someone help or explain this?
Thanks.