Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
type alias HasAnInt = { foo : Int }
badExample : HasAnInt -> HasAnInt
badExample record =
{ record | foo = toString record.foo }
{- Since we're changing the type, we need to give the correct
type annotation for the new return value
-}
thisWorks : HasAnInt -> { foo : String }
thisWorks record =
{ record | foo = toString record.foo }
{- We can also give that new return value a type alias so we
can reuse it in other places, too.
-}
type alias HasAString = { foo : String }
thisAlsoWorks : HasAnInt -> HasAString
thisAlsoWorks record =
{ record | foo = toString record.foo }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment