On Monday, October 24, 2016 at 1:17:30 AM UTC+1, John Kelly wrote:
>
> I'm coming to the sad realization that an api like this is simply not 
> possible:
>
> ```
> session =
>     resource "sessions"
>         { id = int "id"
>         , speaker_id = int "speaker_id"
>         , start_time = string "start_time"
>         , end_time = string "end_time"
>         , location = string "location"
>         , session_type = int "session_type"
>         , speaker = hasOne (\_ -> speaker)
>         }
>
>
> speaker =
>     resource "speakers"
>         { id = int "id"
>         , name = string "name"
>         , sessions = hasMany (\_ -> session)
>         }
> ```
>
> Any ideas? I was under the impression that the lambda would fix the 
> recursive type issue, but now i see that elm still has trouble with the 
> type of the record. 
>

Yes, I also ran into this issue with mutual recursion. I simply followed 
the advice here and created wrapper types for all my records:

https://github.com/elm-lang/elm-compiler/blob/master/hints/recursive-alias.md 

type Session = Session { ... }
type Speaker = Speaker { ... }

Its a bit of a PITA, since you end up having to wrap and unwrap records all 
the time. Defining an unwrap function can help things along:

unwrapSpeaker (Speaker speaker) = speaker

-- 
You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to