作为练习,看看我是否理解map我想要为AZ范围内的每个项目添加一个字符'a' 的功能.
好吧,显然我不会因为我得到这些例外,我不认为是输出:
Prelude> map (++ 'A')['A'..'Z']
<interactive>:46:9:
Couldn't match expected type ‘[a]’ with actual type ‘Char’
Relevant bindings include it :: [[a]] (bound at <interactive>:46:1)
In the second argument of ‘(++)’, namely ‘'A'’
In the first argument of ‘map’, namely ‘(++ 'A')’
In the expression: map (++ 'A') ['A' .. 'Z']
<interactive>:46:14:
Couldn't match expected type ‘[a]’ with actual type ‘Char’
Relevant bindings include it :: [[a]] (bound at <interactive>:46:1)
In the expression: 'A'
In the second …Run Code Online (Sandbox Code Playgroud) 我在作业中遇到了这段代码:
procedure Refs is
type Node is
record
Content : Integer;
Name : Character;
end record;
type XNode is access Node;
type NodeArray is array (Positive range 1 .. 5) of XNode;
[...]
Run Code Online (Sandbox Code Playgroud)
即使在阅读了文档、维基等之后,我似乎也无法理解它(以至于我可以向我的祖母解释它)。
有人可以用简单的术语解释访问关键字的含义吗?
我有一个节点数组:
type NodeArray is array (Positive range 1 .. 5) of XNode;
Run Code Online (Sandbox Code Playgroud)
该节点有一些数据和一个整数ID,但现在这并不重要.
我不记得的方式是array'First(借口滥用符号)总是指向或引用范围或数组中的第一项,而不是范围类型的整数.
我的问题是为什么我总是得到1而不是我的数组中的第一个条目.
如果您需要查看更多可以提供的代码,我只是认为我的示例简单而简洁.
我有一个功能:
fold_wrap :: (a -> a -> a) -> (Prop -> a) -> a -> Wrapper -> a
fold_wrap v x z (Mrappe l r) = v ( v(v x z l) v(v x z r) )
fold_wrap v x z (Wrap f) = x f
fold_warp v x z (Wtail ) = z
Run Code Online (Sandbox Code Playgroud)
我在哪里遇到以下错误:
mast: mast.hs:(15,1)-(16,31): Non-exhaustive patterns in function fold_mast
Run Code Online (Sandbox Code Playgroud)
所以我补充道
fold_wrap v x z _ = z
Run Code Online (Sandbox Code Playgroud)
哪个修正了错误但是
这让我相信某些模式确实无可比拟.
现在我解决这个问题的直觉是打印传递给函数的内容.
所以我加了这个
fold_wrap v x z g = …Run Code Online (Sandbox Code Playgroud)