Type signature for update and view

Hey everyone, I’ve been playing around with Elm, but I’m getting this compile error that I don’t understand: https://ellie-app.com/4qQRZhfJ6tLa1

Don’t mind if code seems a bit weird, I’ve been cutting things out unrelated to the error I’m getting. Can anyone explain why I get an error saying that view and update should only take Msg and no Model?

init should return (Model, Cmd Msg), not (Msg, Cmd Msg). For some reason the compiler error got a bit confusing.

Herteby is right, I made some changes, you can go from there, it compiles now, https://ellie-app.com/4qR8gh4dZGNa1, your model should be an alias type (record type), you defined your model as a custom type

The Model doesn’t have to be a record, it can be whatever you want. A record just tends to be the most practical.

2 Likes

Ok, good point, thanks, as you said, but most common type for modeling Models is a record type, I never had to use a custom type as a model itself.

https://ellie-app.com/4qQRZhfJ6tLa1

Here is a model as custom type

2 Likes

Thanks! I guess the compiler can’t really know better when element is generic, and init is the first function it sees, and reduces the generic arguments based on the types provided there. Oh well ¯\(ツ)

The custom type was on purpose, since it allows me to encode my GUI as a nice graph, where the nodes are the variants of my Model and my Msgs are the edges connecting the nodes.

Once I start having state I want to share between different views, I imagine I’ll do something like this:

type alis Model = 
{ view : ViewCustomType
, dataStore : SharedDataModel
}

That way I can encode both :slight_smile:

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