haskell 中类型的函数应用程序操作数 ($)?

San*_*lar 6 haskell

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。

chi*_*chi 7

一个可能的解决方案是定义您自己的类型运算符$

{-# LANGUAGE TypeOperators, PolyKinds #-}

type ($) a = a
Run Code Online (Sandbox Code Playgroud)

  • 我认为更好的是:“输入 ($) a = a”。 (2认同)
  • 请注意,任何解决方案都应使用“PolyKinds”。 (2认同)