我知道TypeSynomymInstances只允许在实例头中使用完全应用的类型同义词,但是如果我可以使用paritally应用的类型同义词,它似乎也很方便.
例如:
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 …Run Code Online (Sandbox Code Playgroud) 我正在尝试运行以下代码:
http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.39.8039&rep=rep1&type=pdf
运用 ghci 7.6.3
{-# LANGUAGE LiberalTypeSynonyms, TypeSynonymInstances #-}
type C m a = (a -> Action m) -> Action m
data Action m = Atom (m (Action m)) | Fork (Action m) (Action m) | Stop
Run Code Online (Sandbox Code Playgroud)
这个原始形式:
instance (Monad m) => Monad (C m) where
f >>= k = \c -> f (\a -> k a c)
return x = \c -> c x
Run Code Online (Sandbox Code Playgroud)
给出了这个错误:
Type synonym `C' should have 2 arguments, but has been given 1
In …Run Code Online (Sandbox Code Playgroud)