On Wednesday, February 15, 2017 at 8:49:13 PM UTC, Rupert Smith wrote: > > What I don't understand is why this fails to type check: > > mapWhenWithPosition : (WithPosition b -> a) -> State -> Maybe a > mapWhenWithPosition func state = > case state of > Aware rect -> > Just <| func rect > > Active rect -> > Just <| func rect > > Inactive rect -> > Just <| func rect > > _ -> > Nothing >
I can get it to type check by defining the more general function in a let..in construct: mapWhenWithPosition : (WithPosition {} -> a) -> State -> Maybe a mapWhenWithPosition func state = let func_ : WithPosition b -> a func_ { rect } = func { rect = rect } in case state of Aware position -> Just <| func_ position Active position -> Just <| func_ position Inactive position -> Just <| func_ position _ -> Nothing let..in behaves somewhat like the existential qualifier - "let us say that a more general type exists, by defining its implementation". I still have to unpack and repack the record but at least now, only once. -- 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 elm-discuss+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.