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.
Still, Bartosz Milewski's excellent 2017 book "Category
Theory for Programmers" is very much recommended!
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
Paul Rubin <no.email@nospam.invalid> wrote or quoted:
The article "Fast and loose reasoning is morally correct", about typing
judgments in the presence of bottom and seq, might be of interest here.
Yes, I know - because exactly this is what the book said.
I just omitted it for brevity. But here's the full quotation:
|From the pragmatic point of view, itrCOs okay to ...
On 19/04/2026 19:51, Stefan Ram wrote:
-- Both types have the exact same "extension" (two Integers)Why do you call the two integers the "extension" ?
data Apple = Apple Int Int
data Orange = Orange Int Int
Tristan Wibberley <tristan.wibberley+netnews2@alumni.manchester.ac.uk> wrote or quoted:
On 19/04/2026 19:51, Stefan Ram wrote:
-- Both types have the exact same "extension" (two Integers)Why do you call the two integers the "extension" ?
data Apple = Apple Int Int
data Orange = Orange Int Int
... Haskell does /not/ deem them to be equal, which shows that
Haskell types are /not/ mathematical sets.
On 12/06/2026 00:05, Stefan Ram wrote:
... Haskell does /not/ deem them to be equal, which shows thatOr they don't have the same elements:
Haskell types are /not/ mathematical sets.
(ctorlabel-Apple, 0, 12) is not in Orange, and
(ctorlabel-Orange, 0, 12) is not in Apple
(ctorlabel-Apple, 0, 12) is an internal compiler symbol,
but it is not part of the Haskell language proper, syntax,
or specification. What you see in the language are then exactly
these types as names (or as tags / labels), not types as sets.
| Sysop: | Amessyroom |
|---|---|
| Location: | Fayetteville, NC |
| Users: | 74 |
| Nodes: | 6 (0 / 6) |
| Uptime: | 05:10:08 |
| Calls: | 1,194 |
| Files: | 1,353 |
| D/L today: |
2 files (1,590K bytes) |
| Messages: | 291,507 |