Lamdera ToBackend type mismatch

I’m trying to organize my Lamdera app’s codebase similar to GitHub - supermario/lamdera-realworld: Lamdera port of elm-spa realworld implementation, adding a full backend implementation..

Definition of Types.ToBackend:

type alias ToBackend =
    Bridge.ToBackend

Definition of Bridge.ToBackend:

type ToBackend
    = Foo

In Pages/Home.elm, in update, I’m trying to return this:

( model
, Lamdera.sendToBackend Foo
)

But i get a cumpiler error. It says that Foo is a Bridge.ToBackend value, but sendToBackend needs it to be Types.Backend

Hey @DullBananas!

Just on the off-chance, are you sure you’ve got the latest compiler? The bridge alias trick is a more recent feature to allow breaking import cycles.

Short of that I’m not 100% sure what the issue is, are you modifying lamdera-realworld or trying to replicate it from scratch? If the latter, am I able to see your source somewhere? Might be easier to spot the issue in full context :blush:

Here is an SSCCE (relevant parts of my code).

Main/Test.elm is a module with the type mismatch error.

@DullBananas great, thank you!

So the issue is you’ve used Main/Bridge.elm instead of Bridge.elm. If you change the module name and fix up the imports, it should compile!

Right now core type placements are special cased in the compiler and expected to be very specifically named. Perhaps in future this could be cleverer and detect intent based on usage, but right now Types.elm and Bridge.elm are special and should be the modules used.

Let me know if you get stuck on anything else!

4 Likes

add that to Lamdera’s documentation