Haskell 中的类型是否有 ($) 等价物?
如果我有一个带参数的类型
data myType a b c = ...
Run Code Online (Sandbox Code Playgroud)
像这样应用 monad 会很好:
f :: input -> errorMonad $ myType a b c
{- throws error:
Not in scope: type constructor or class ‘$’. -}
Run Code Online (Sandbox Code Playgroud)
我可以得到同样的效果
f :: input -> errorMonad (myType a b c)
Run Code Online (Sandbox Code Playgroud)
但不是很清楚 IMO。
一个可能的解决方案是定义您自己的类型运算符$:
{-# LANGUAGE TypeOperators, PolyKinds #-}
type ($) a = a
Run Code Online (Sandbox Code Playgroud)