Is there a legitimate reason for `never`

Can you argue that? What if you want to write a function with the signature Error () -> String (using Unit instead of Never) that renders errors. How do you handle the CustomError ()? Generate an empty string? I guess you’d be losing lots of compiler guarantees there.


This is kind of off-topic, but I usually don’t use Never to define my Phantom type parameter values. This has the advantage that I can specify what coordinate system I generate events for explicitly, like this:

type ScreenCoordinate = ScreenCoordinate

type ElementCoordinate = ElementCoordinate

onMouseDown : coordinateSystem -> (Point coordinateSystem -> msg) -> Attribute msg
onMouseDown _ produceMsg = ...

-- used like this
div
    [ class "main-content"
    , onMouseDown ScreenCoordinate ClickMain
    , style "position" "relative"
    ]
    [ div
        [ class "positioned-element"
        , style "position" "absolute"
        , style "top" model.elementY
        , onMouseDown ElementCoordinate ClickElement
        ]
        []
    ]
1 Like

Yes you would loose compiler guarantees because 1 /= 0 but you loose compiler guarantees with original example as described here as well. Anyway, if you assume nothing will ever construct that unit type you pretty much don’t care what you put into that brach. It doesn’t even have to an string, you can do infinit recursion.

Ah cool! I didn’t know elm docs include this appendix now, that is very helpful indeed.

yes definitely that why said it’s correct. The usage of unit in its place is just a possible workaround which is less precise but might be potentially argued as good enough solution if one wants to crate case for removing Never type (which I personally don’t think is a good idea). I think this is why the algebraic intuition is the most compelling as it’s easy to illustrate that 0 is neither variable nor 1

msg identity will just explode at runtime, so it doesn’t really construct anything…

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