Created
August 11, 2017 14:57
-
-
Save jdeisenberg/0ee8864a8e30e31726225382106b9b68 to your computer and use it in GitHub Desktop.
Confusing output from purescript REPL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
> :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. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For the record, here is the issue: when I call the function, pattern matching unwraps the record from the
Cat
Usingtype
as an alias would allow direct access tomyCat.name
, but doesn't have the type safety ofnewtype
.