Skip to content

Instantly share code, notes, and snippets.

@jdeisenberg
Created August 11, 2017 14:57
Show Gist options
  • Save jdeisenberg/0ee8864a8e30e31726225382106b9b68 to your computer and use it in GitHub Desktop.
Save jdeisenberg/0ee8864a8e30e31726225382106b9b68 to your computer and use it in GitHub Desktop.
Confusing output from purescript REPL
> :clear
> import Prelude
> newtype Cat = Cat {name::String, breed::String}
> myCat = Cat {name: "Marco", breed: "Domestic shorthair"}
> :t myCat
Cat
> :paste
… getName :: Cat -> String
… getName (Cat c) = c.name
> getName myCat
"Marco"
> myCat.name
Error found:
in module $PSCI
at line 1, column 1 - line 1, column 6
Could not match type
{ name :: t0
| t1
}
with type
Cat
while checking that type Cat
is at least as general as type { name :: t0
| t1
}
while checking that expression myCat
has type { name :: t0
| t1
}
while checking type of property accessor myCat.name
in value declaration it
where t0 is an unknown type
t1 is an unknown type
See https://github.com/purescript/documentation/blob/master/errors/TypesDoNotUnify.md for more information,
or to contribute content related to this error.
@jdeisenberg
Copy link
Author

For the record, here is the issue: when I call the function, pattern matching unwraps the record from the Cat Using type as an alias would allow direct access to myCat.name, but doesn't have the type safety of newtype.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment