Skip to content

Instantly share code, notes, and snippets.

@zwilias
Last active September 16, 2017 13:35
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zwilias/28da939bc3cbbfdf4af28d6db31c74d3 to your computer and use it in GitHub Desktop.
Save zwilias/28da939bc3cbbfdf4af28d6db31c74d3 to your computer and use it in GitHub Desktop.
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