开始练习以掌握所学的Haskell技能。
module Clock (addDelta, fromHourMin, clockDecons) where
data Clock = Clock { hours :: Int
, mins :: Int
} deriving Show
fromHourMin :: Int -> Int -> Clock
fromHourMin hour min = Clock {hours = hour, mins = min}
-- toString :: Clock -> String
clockDecons clock = (hs,ms)
where hs = hours
ms = mins
addDelta :: Int -> Int -> Clock -> Clock
addDelta hour min clock = undefined
Run Code Online (Sandbox Code Playgroud)
整整一天之后,可能有些阴云密布,但是为什么出现:
<interactive>:15:1: error:
• No instance for (Show (Clock -> Int))
arising from a use of ‘print’
(maybe you haven't applied a function to enough arguments?)
• In a stmt of an interactive GHCi command: print it
Run Code Online (Sandbox Code Playgroud)
我什至还没有开始创建时钟的字符串实例。
你可能是说
clockDecons :: Clock -> (Int, Int)
clockDecons clock = (hours clock, mins clock)
Run Code Online (Sandbox Code Playgroud)