相关疑难解决方法(0)

为什么TypeSynonymInstances不允许在实例头中使用部分应用的类型同义词?

我知道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)

haskell

24
推荐指数
2
解决办法
2751
查看次数

将类型定义为Monad

我正在尝试运行以下代码:

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)

monads haskell

1
推荐指数
1
解决办法
274
查看次数

标签 统计

haskell ×2

monads ×1