gpt4 book ai didi

Haskell 练习解构记录语法

转载 作者:行者123 更新时间:2023-12-02 00:16:08 25 4
gpt4 key购买 nike

开始练习以复习所学的 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

可能在一整天后有点模糊,但为什么我得到:

<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

我什至还没有开始创建时钟的字符串实例。

最佳答案

你可能是说

clockDecons :: Clock -> (Int, Int)
clockDecons clock = (hours clock, mins clock)

关于Haskell 练习解构记录语法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56938762/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com