Yes, I'm just reading a book by a man who said types are sets
and then goes on to "demonstrate" this using Haskell.
I know nothing about Haskell, but I was mistrustful immediately.
And here's the demo (my demo, not the book's demo):
-- Both types have the exact same "extension" (two Integers)
data Apple = Apple Int Int
data Orange = Orange Int Int
-- A function that only accepts an Apple
checkApple :: Apple -> String
checkApple _ = "This is an Apple"
main :: IO ()
main = do
let myFruit = Orange 1 2
-- The line below causes a COMPILE ERROR.
-- Even though Orange has the same structure as Apple,
-- the names are different, so the types are NOT equal.
putStrLn (checkApple myFruit)
. Both types have the same extension, but different names.
And Haskell does /not/ treat them to be equal.
I'm curious: what did *his* demo look like? Perhaps he was doing
something with typeclasses?
. So he says that Haskell types are not exactly sets, but
according to him this is because they have the additional
value "bottom" ("_|_"), otherwise they would be sets as I
understand him.
He does not actually wrote a demo for this interpretation,
he just explained it as quoted above.
The article "Fast and loose reasoning is morally correct", about typing >judgments in the presence of bottom and seq, might be of interest here.
| Sysop: | Amessyroom |
|---|---|
| Location: | Fayetteville, NC |
| Users: | 65 |
| Nodes: | 6 (0 / 6) |
| Uptime: | 05:08:11 |
| Calls: | 862 |
| Files: | 1,311 |
| D/L today: |
921 files (14,318M bytes) |
| Messages: | 264,602 |