我在haskell中制作了一个计算器,我在GHCi中运行.但是由于最终的数字可以是整数或双数,所以我做了类型声明
calc :: String -> Either Integer Double
Run Code Online (Sandbox Code Playgroud)
但是,该功能的输出总是在其前面左侧或右侧
Left 7
Right 8.4
Run Code Online (Sandbox Code Playgroud)
有没有办法可以阻止左右打印?
我一直在寻找年龄来尝试找到一种简单的方法来获取当前时间(可能是从午夜,或小时,分钟,秒的秒数)到int.有人能指出我正确的方向吗?我查看了图书馆并没有成功.
假设我有一个名为foo的ADT
data foo = N Integer | V Var | Div foo foo
Run Code Online (Sandbox Code Playgroud)
有没有办法在模式匹配中使用ADT,所以我不必写出每种可能的数据类型组合?
myfunc :: foo -> [Var]
myfunc (N _) = []
myfunc (V a) = [a]
myfunc (Div (foo) (foo)) = myfunc(foo) ++ myfunc(foo)
Run Code Online (Sandbox Code Playgroud)
有没有办法做这样的工作,所以我不必写
myfunc (Div (N a) (N b)) = myfunc(N a) ++ myfunc(N b)
myfunc (Div (V a) (N b)) = myfunc(V a) ++ myfunc(N b)
myfunc (Div (N a) (V b)) = myfunc(N a) ++ myfunc(V b)
...
Run Code Online (Sandbox Code Playgroud)
等等