【发布时间】:2014-06-10 13:14:03
【问题描述】:
我也有函数:
higherOrderPure :: (a -> b) -> c
effectful :: Monad m => (a -> m b)
我想将第一个函数应用到第二个函数:
higherOrderPure `someOp` effectful :: Monad m => m c
在哪里
someOp :: Monad m => ((a -> b) -> c) -> (a -> m b) -> m c
例子:
curve :: (Double -> Double) -> Dia Any
curve f = fromVertices $ map p2 [(x, f x) | x <- [1..100]]
func :: Double -> Either String Double
func _ = Left "Parse error" -- in other cases this func can be a useful arithmetic computation as a Right value
someOp :: ((Double -> Double) -> Dia Any) -> (Double -> Either String Double) -> Either String (Dia Any)
someOp = ???
curve `someOp` func :: Either String (Dia Any)
【问题讨论】:
-
map p2 (x, f x)应该做什么?map p2暗示p2是一个函数,所以(x, f x)必须是一个列表,但它显然是一个元组。我也怀疑Dia类型只是列表的别名,因为curve f = [...],意味着curve返回一个列表。您可以用一个工作示例更新您的问题吗?包含p2和fromVertices的类型签名也可能会有所帮助。 -
抱歉,错字,在 p2 之后缺少一个 [
-
这样更容易理解发生了什么,谢谢!
-
您使用哪个库来执行此操作?我想浏览它的文档,看看这个问题是否可以按照你想要的方式解决
-
projects.haskell.org/diagrams,但这有点无关紧要,问题更像是理论上的,示例只是为了更好地理解。