【发布时间】:2019-12-23 22:06:42
【问题描述】:
我试图实现多态元组映射,并最终在 GHCi 中编写了以下代码:
data MaxS = MaxS
class Strategy action input result | input -> result where
work :: action -> input -> result
instance (Ord a) => Strategy MaxS (a, a, a) a where work _ (a, b, c) = max a (max b c)
f :: (Strategy action input result) => action -> input -> result ; f a i = work a i
f MaxS (1, 2, 3)
<interactive>:91:1: error:
* No instance for (Ghci13.Strategy
MaxS (Integer, Integer, Integer) ())
arising from a use of `it'
* In the first argument of `print', namely `it'
In a stmt of an interactive GHCi command: print it
f MaxS (1, 2, 3) :: Integer
3
所以我的问题是为什么在没有指定的情况下选择 Unit 类型以及如何避免明显的返回类型定义。
【问题讨论】:
标签: haskell types ghc type-inference