约束newtype参数

时间:2012-11-29 04:34:31

标签: haskell typeclass

拥有以下自定义新类型:

newtype QueryM a = QueryM (Connection -> IO a) 

如何在限制Alternative拥有a实例的同时为其声明Alternative个实例?或者我可以吗?

我的意思是这样的:

instance (Alternative a) => Alternative (QueryM a) where

1 个答案:

答案 0 :(得分:4)

如果我在a添加参数,请在此处编译好:

import Control.Applicative

newtype QueryM a b = QueryM (Connection -> IO (a b))

type Connection = ()

instance Functor (QueryM a)
instance Applicative (QueryM a)

instance (Alternative a) => Alternative (QueryM a) where