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 -> > 105: Just <| func rect > > Active rect -> > Just <| func rect > > Inactive rect -> > Just <| func rect > > _ -> > Nothing > > This would seem to make extensible records a lot less useful than they > could be. Is this one of those cases where an existential qualifier would > be needed to specify the type of the function? Or is this in fact a case > that could be typed in Elm without problem and that the type checker should > accept? >
Ok, I think I get it. Expecting this function to type check is a analagous to expecting this function to type check: badFunc : (a -> a) -> String -> String badFunc func val = func val This would work if I did: badFunc identity "test" or badFunc toUpper "test" but not if I have (square : Int -> Int) badFunc square "test" Similarly I could have a function that matches the type (WithPosition b -> a), but this particular function will require more fields than 'rect'. funcThatBreaksIt : (WithPositon b -> a) funcThatBreaksIt { rect, and, some, other, fields } -> whereWillTheValuesForTheseComeFrom and some other fields There is an implicit forAll qualifer over the type parameters in a typing expression. The argument to a function passed to another function must be contra-variant with respect to the 'more general type' relation amongst types. So, this is one of those cases where an existential qualifier would be needed to specify the type of the function. That would break type inference, so it is excluded. -- 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.