mathelminfinity

Does elm have a constant for infinity?


According to this: http://package.elm-lang.org/packages/elm-lang/core/latest/Basics#isNaN

Elm supports infinity and considers it a number. Right now I am using inf = 1/0 as a constant but I want to know how I can import infinity, instead of defining it.

So, does Elm have a constant for infinity and how do I import it?


Solution

  • I see you already have an answer, but here is one way to emulate inifinty using a Maybe

    infinity =
        Nothing
    
    
    lessThan : Int -> Maybe Int -> Maybe Int
    lessThan x y =
        case y of
            Just y_ ->
                if x < y_ then
                    Just x
    
                else
                    y
    
            Nothing ->
                Just x