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。
我需要用一个表格制作一些文档,该表格的单元格有两行(它是代码,所以它需要位于单独的行上)。但是如果我尝试
{-
+----------+------------------+
| Col1 | Col2 |
+==========+==================+
| One line | This should span |
| | Two lines |
+----------+------------------+
-}
Run Code Online (Sandbox Code Playgroud)
它给出与使用相同的结果
{-
+----------+---------------------------+
| Col1 | Col2 |
+==========+===========================+
| One line | This should spanTwo lines |
+----------+---------------------------+
-}
Run Code Online (Sandbox Code Playgroud)
有没有办法强制换行?
更重要的是,表内的代码怎么样?我可以使它成为多行吗?
显然这是行不通的
{-
+----------+------------------+
| Col1 | Col2 |
+==========+==================+
| One line | @This is code |
| | Other code line@|
+----------+------------------+
-}
Run Code Online (Sandbox Code Playgroud)
以下方法有效,但再次生成一个只有一行的单元格:
{-
+----------+------------------+
| Col1 | Col2 |
+==========+==================+
| …Run Code Online (Sandbox Code Playgroud) 我想编写一个可以在数字(例如1)和字符串(例如"a")上调用的函数。在我的应用程序中尽可能地简化“用户代码”很重要。
我的代码的最小示例如下所示
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE TypeSynonymInstances #-}
type StrInt = Either String Int
class Lift a where
toStrInt :: a -> StrInt
instance Lift String where
toStrInt= Left
instance Lift Int where
toStrInt= Right
declare:: StrInt ->String
declare (Left a) = "String: " ++ a
declare (Right n) = "Number: " ++ (show n)
declare' :: Lift a => a -> String
declare' a = declare (toStrInt a)
myDecA = declare' "a"
myDec1 …Run Code Online (Sandbox Code Playgroud) 使用:tI 可以打印表达式的类型。但是我如何查看该类型的构造函数呢?emacs 的 Haskell 模式下是否有快捷方式?
这似乎是一个基本的东西,但我找不到它。也许我只是搜索了错误的术语......
一般来说,无需查看文档即可查看打印类型定义的最简单方法是什么。