如何在函数式语言中定义复合函数,特别是使用Ocaml?例如,如果我编写一个计算另一个函数结果否定的函数,那就是:not(f(x))where f(x)返回一个布尔值.我该如何定义它?
我在创建包含异构元素的集合时遇到问题,特别是元素的结构如下:
(a,1),((a,1),1)),((a,1),1),1)等......
我可以使用模块Set of ocaml吗?
还有一些功能允许我在集合之间制作笛卡尔积(也是异构的)?
我正在写一个包含一些"for"循环的ocaml程序,我的问题是,对于每个循环,你会收到这条消息:"警告10:这个表达式应该有类型单位."
示例:
let f q p rho=
let x = [] in
if q > p then
for i=0 to rho do
x= q :: x
done;
x;;
Run Code Online (Sandbox Code Playgroud)
每次我使用"for"循环时,我该如何解决这个问题?
我编写了用于分解布尔函数的函数,问题是编译我得到了这个:"警告5:这个函数应用程序是部分的,可能缺少一些参数." 我怎么解决这个问题?我设置了错误的模式匹配,或者我无法通过模式匹配来运行此操作
代码如下:
let rec decomposition state_init state prec formula =
match formula with
And form -> (fun () ->
let f1 = List.hd form in
let f2 = And(List.tl form )in
let new_state = Forms (state_init,f1) in
decomposition state_init new_state state f1;
decomposition state_init new_state state f2;
Hashtbl.add graph new_state (("",false,state :: []) , []) ;
let x = Hashtbl.find graph state in
let succ = state :: snd x in
let (desc,last,ptrs) = fst x in
Hashtbl.replace graph …Run Code Online (Sandbox Code Playgroud) 我想问你是否可以在用Ocaml编写的程序中调用用python编写的程序,如果答案是肯定的,我该怎么办?
如果我必须将数据类型反汇编为可变大小,我仍然可以使用"匹配和使用,如果答案是肯定的,你可以帮我弄清楚(我是这种语言的初学者),或者我还是用其他方法.
定义的类型是这样的:
type 'state formula =
| And of 'state formula list
| Or of 'state formula list
| Literal of bool
| Variable of 'state
Run Code Online (Sandbox Code Playgroud)
从我看过的例子中我看到"匹配和用"是静态类型的结构,在我的情况下是这样的吗?
我想询问是否异常:"异常Stack_overflow"可能导致无限循环,特别是,以下代码中发生异常:
( *the loop "while" should stop when both stacks are empty*)
while (not (Stack.is_empty stackFalse) )|| ( not (Stack.is_empty stackTrue)) do
(
if (not ( Stack.is_empty stackTrue )) then
(
let q1 = Stack.pop stackTrue in
let (_,_,ptrs) = fst (Hashtbl.find graph ( fst q1) ) in
List.iter ( fun elem ->
let app = Hashtbl.find graph elem in
let (typeNode,last,ptrs') = fst app in
if typeNode = "Or-node" then
(
Stack.push (elem,true) stackTrue;
Hashtbl.add labeled elem true
) …Run Code Online (Sandbox Code Playgroud) 我正在使用parsec Haskell库.
我想解析以下类型的字符串:
[[v1]][[v2]]
xyz[[v1]][[v2]]
[[v1]]xyz[[v2]]
Run Code Online (Sandbox Code Playgroud)
等等
我很有意思只收集值v1和v2,并将它们存储在数据结构中.
我尝试使用以下代码:
import Text.ParserCombinators.Parsec
quantifiedVars = sepEndBy var (string "]]")
var = between (string "[[") (string "") (many (noneOf "]]"))
parseSL :: String -> Either ParseError [String]
parseSL input = parse quantifiedVars "(unknown)" input
main = do {
c <- getContents;
case parse quantifiedVars "(stdin)" c of {
Left e -> do { putStrLn "Error parsing input:"; print e; };
Right r -> do{ putStrLn "ok"; mapM_ print r; };
}
}
Run Code Online (Sandbox Code Playgroud)
这样,如果输入 …
我在编译用ocaml编写的程序时遇到问题,出现的错误是:错误:未绑定模块基础知识,我该如何解决这个问题?我说这个语言的初学者.
整个代码中使用的库是:open Basics ;; 开放Paritygame ;; 打开Univsolve ;; 开放的Solvers ;;
包含模块的文件是:basics.ml basics.mli,paritygame.ml paritygame.mli,univsolve.ml univsolve.mli和solvers.ml solvers.mli .....
我会遇到这个问题:给出这个规则
defField: type VAR ( ',' VAR)* SEP ;
VAR : ('a'..'z'|'A'..'Z')+ ;
type: 'Number'|'String' ;
SEP : '\n'|';' ;
Run Code Online (Sandbox Code Playgroud)
我需要做的是将模板与规则"defField"相关联,该规则返回表示字段的xml-schema的字符串,即:
Number a,b,c ;-> "<xs:element name="a" type = "xs:Number"\>" ,also for b and c.
Run Code Online (Sandbox Code Playgroud)
我的问题出现在Kleene的*中,也就是说,如何根据'*'编写模板来执行上面描述的操作?
谢谢!!!