haskell - Haskell TypeSynonymInstances 实例声明
问题描述
尝试使用 ghci> 加载文件时出现以下错误:l myfile.hs
• Illegal instance declaration for ‘ExpSYM String’
(All instance types must be of the form (T t1 ... tn)
where T is not a synonym.
Use TypeSynonymInstances if you want to disable this.)
• In the instance declaration for ‘ExpSYM String’
在行中:实例 ExpSYM String where
class ExpSYM repr where
lit :: Int -> repr
neg :: repr -> repr
add :: repr -> repr -> repr
instance ExpSYM Int where
lit n = n
neg e = - e
add e1 e2 = e1 + e2
eval :: Int -> Int
eval = id
instance ExpSYM String where
lit n = show n
neg e = "(−" ++ e ++ ")"
add e1 e2 = "(" ++ e1 ++ " + " ++ e2 ++ ")"
view :: String -> String
view = id
起初我以为这是因为双实例 ExpSYM,但如果我删除第一个(实例 ExpSYM Int)并且它是 eval,我仍然会看到错误。怎么修?问题是什么?
解决方案
推荐阅读
- reactjs - 移动(拖动)时如何更新我的标记的新位置?使用 React 传单
- reactjs - TypeError:null 不是对象(评估'RNRandomBytes.seed')React Native
- kuzzle - 错误:无法连接到位于 127.0.0.1:7512 的 kuzzle 服务器:连接丢失。(ws 状态=503)
- join - Apache Flink:我们可以从窗口连接应用函数中获取 windowStartTime 和 windowEndTime 吗?
- gatling - Gatling tryMax 即使重试成功也报错
- css - :nth-child (或类似)公式仅在存在少于三个子元素时才隐藏 div (需要是 CSS)
- c++ - 无法在不敏感的情况下比较字符串/字符(错误 - 未找到方法)
- pandas - Pandas:如何根据多个条件创建新列?
- reactjs - 使用 Touch API 和 Drag API 拖放
- python - python 3.8中字典的pop操作