作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我知道TypeSynomymInstances only allows fully applied type synonyms to be used in instance heads ,但如果我也可以使用部分应用的类型同义词似乎会很方便。
例如:
class Example e where
thingy :: a -> b -> e a b
-- legit, but awkward
newtype FuncWrapper e a b = FuncWrapper { ap :: a -> e a b }
instance (Example e) => Example (FuncWrapper e) where
thingy _ = FuncWrapper . flip thingy
funcWrapperUse :: (Example e) => e Int String
funcWrapperUse = thingy 1 "two" `ap` 3 `ap` 4 `ap` 5
-- not legal, but a little easier to use
type FuncSynonym e a b = a -> e a b
instance (Example e) => Example (FuncSynonym e) where
thingy _ = flip thingy
funcSynonymUse :: (Example e) => e Int String
funcSynonymUse = thingy 1 "two" 3 4 5
最佳答案
Haskell 中根本不允许使用部分应用的类型同义词。部分应用的同义词实际上是一个函数,其输入是未应用的类型,其输出是一个类型。例如,这里是 bool 逻辑的编码:
type True x y = x
type False x y = y
type Not b x y = b y x
type And b1 b2 x y = b1 (b2 x y) y
type Or b1 b2 x y = b1 x (b2 x y)
关于haskell - 为什么 TypeSynonymInstances 不允许在实例头中使用部分应用的类型同义词?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4922560/
我知道TypeSynomymInstances only allows fully applied type synonyms to be used in instance heads ,但如果我也可
我正在阅读 Real World Haskell Pg 151,我已经盯着以下段落看了一个多小时: Recall that String is a synonym for [Char], which
我是一名优秀的程序员,十分优秀!