module NumberInput exposing (..) type alias Model a = { value : a , original : String , convert : String -> Maybe a } fromFloat : Float -> Model Float fromFloat x = Model x (String.fromFloat x) String.toFloat fromInt : Int -> Model Int fromInt x = Model x (String.fromInt x) String.toInt get : Model a -> a get = .value update : String -> Model a -> Model a update str model = case model.convert str of Nothing -> model Just value -> { model | value = value, original = str } show : Model a -> String show = .original