計算機科学のブログ

型の紹介 型クラス :infoコマンド、Word型、Int型、Bounded、maxBound、minBound

入門Haskellプログラミング (Will Kurt(著)、株式会社クイープ(監修、翻訳)、翔泳社)のUNIT2(型の紹介)、LESSON 13(型クラス)、13.8(練習問題)Q13-1の解答を求めてみる。

入出力結果(Terminal, Zsh)

% ghci
GHCi, version 8.10.7: https://www.haskell.org/ghc/  :? for help
macro 'doc' overwrites builtin command.  Use ':def!' to overwrite.
(0.00 secs, 0 bytes)
(0.00 secs, 0 bytes)
Loaded GHCi configuration from /Users/…/.ghc/ghci.conf
Prelude
λ> :info Int
type Int :: *
data Int = GHC.Types.I# GHC.Prim.Int#
  	-- Defined in ‘GHC.Types’
instance Eq Int -- Defined in ‘GHC.Classes’
instance Ord Int -- Defined in ‘GHC.Classes’
instance Enum Int -- Defined in ‘GHC.Enum’
instance Num Int -- Defined in ‘GHC.Num’
instance Real Int -- Defined in ‘GHC.Real’
instance Show Int -- Defined in ‘GHC.Show’
instance Read Int -- Defined in ‘GHC.Read’
instance Bounded Int -- Defined in ‘GHC.Enum’
instance Integral Int -- Defined in ‘GHC.Real’
Prelude
λ> :info Word
type Word :: *
data Word = GHC.Types.W# GHC.Prim.Word#
  	-- Defined in ‘GHC.Types’
instance Eq Word -- Defined in ‘GHC.Classes’
instance Ord Word -- Defined in ‘GHC.Classes’
instance Enum Word -- Defined in ‘GHC.Enum’
instance Num Word -- Defined in ‘GHC.Num’
instance Real Word -- Defined in ‘GHC.Real’
instance Show Word -- Defined in ‘GHC.Show’
instance Read Word -- Defined in ‘GHC.Read’
instance Bounded Word -- Defined in ‘GHC.Enum’
instance Integral Word -- Defined in ‘GHC.Real’
Prelude
λ> minBound :: Int
-9223372036854775808
it :: Int
(0.01 secs, 81,016 bytes)
Prelude
λ> minBound :: Word 
0
it :: Word
(0.01 secs, 63,656 bytes)
Prelude
λ> maxBound :: Int
9223372036854775807
it :: Int
(0.01 secs, 76,904 bytes)
Prelude
λ> maxBound :: Word
18446744073709551615
it :: Word
(0.00 secs, 77,640 bytes)
Prelude
λ> :quit 
Leaving GHCi.
%