haskell - Haskell 练习解构记录语法
问题描述
开始练习以复习所学的 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)
推荐阅读
- python - Why GUI should use call_soon_threadsafe() when talking to asyncio loop
- javascript - 如何正确调用从第三方脚本导入的 js 模块
- html - 如何在烧瓶 wtf 中使用自定义标签?
- google-cloud-platform - 在 gitops 原理中使用 Gitlab、Terraform、Flux 和 GKE 的最佳方式
- java - 无法在多人游戏中注册自定义剑
- json - 通过 FileMaker Pro 使用 JSON cURL 更新补丁 Microsoft Graph API Planner 任务详细信息产生错误 204
- mysql - 在具有多个值的插入中的主键冲突是否可以继续使用有效值?
- iis - IIS Windows 身份验证在 SERVER 上不断提示
- angular - ag-grid 单元格编辑只允许数字
- javascript - React 中的获取请求:如何映射对象数组中的 JSON 对象数组?