読者です 読者をやめる 読者になる 読者になる

by shigemk2

当面は技術的なことしか書かない

自動導出4 曜日

Haskell
data Day = Monday | Tuesday | Wednesday | Thursday | Friday |
           Saturday | Sunday
                      deriving (Eq, Ord, Show, Read, Bounded, Enum)


-- *Main> Wednesday
-- Wednesday
-- *Main> show Wednesday
-- "Wednesday"
-- *Main> read "Saturday" :: Day
-- Saturday
-- *Main> Saturday == Sunday
-- False
-- *Main> Saturday == Saturday
-- True
-- *Main> Saturday > Friday
-- True
-- *Main> Monday `compare` Wednesday
-- LT
-- *Main> minBound :: Day
-- Monday
-- *Main> maxBound :: Day
-- Sunday
-- *Main> succ Monday
-- Tuesday
-- *Main> pred Saturday
-- Friday
-- *Main> pred Monday
-- *** Exception: pred{Day}: tried to take `pred' of first tag in enumeration
-- *Main> pred Sunday
-- Saturday
-- *Main> [Thursday .. Sunday]
-- [Thursday,Friday,Saturday,Sunday]
-- *Main> [minBound .. maxBound] :: [Day]
-- [Monday,Tuesday,Wednesday,Thursday,Friday,Saturday,Sunday]
-- *Main> [minBound .. maxBound]

-- <interactive>:50:2:
--     Ambiguous type variable `t0' in the constraints:
--       (Bounded t0)
--         arising from a use of `minBound' at <interactive>:50:2-9
--       (Enum t0)
--         arising from the arithmetic sequence `minBound .. maxBound'
--         at <interactive>:50:1-22
--     Probable fix: add a type signature that fixes these type variable(s)
--     In the expression: minBound
--     In the expression: [minBound .. maxBound]
--     In an equation for `it': it = [minBound .. maxBound]