Groups | Search | Server Info | Login | Register


Groups > comp.lang.haskell > #638

Types

From ram@zedat.fu-berlin.de (Stefan Ram)
Newsgroups comp.lang.haskell
Subject Types
Date 2026-04-19 18:51 +0000
Organization Stefan Ram
Message-ID <types-20260419194256@ram.dialup.fu-berlin.de> (permalink)

Show all headers | View raw


  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.

  So I, with no knowledge of Haskell, immediately knew Haskell better
  than a man who wrote a book that is partially about Haskell.

  This is called "nominal typing" what Haskell does here. A type
  essentially is a name, like "Apple" or "Orange". Two different
  names - two different types.

Back to comp.lang.haskell | Previous | NextNext in thread | Find similar


Thread

Types ram@zedat.fu-berlin.de (Stefan Ram) - 2026-04-19 18:51 +0000
  Re: Types Jonathan Lamothe <jonathan@jlamothe.net> - 2026-04-19 17:17 -0400
    Re: Types ram@zedat.fu-berlin.de (Stefan Ram) - 2026-04-20 10:32 +0000
      Re: Types Paul Rubin <no.email@nospam.invalid> - 2026-04-20 11:19 -0700
        Re: Types ram@zedat.fu-berlin.de (Stefan Ram) - 2026-04-20 19:32 +0000

csiph-web