gpt4 book ai didi

module - OCaml 此函数应用于太多参数

转载 作者:行者123 更新时间:2023-12-01 10:58:22 27 4
gpt4 key购买 nike

这只是我编写的一个简单程序,目的是为了更好地理解模块。我正在尝试使用 Id("a",Int) 调用 toS 函数,但似乎我可以像这样编写类型 ast。可能是什么问题?

module Typ =
struct
type typ = Int | Bool
end

module Symbol =
struct
type t = string
end

module Ast =
struct
type ast = Const of int * Typ.typ | Id of Symbol.t * Typ.typ
let rec toS ast = match ast with Id(a,b) -> "a"
|_->"b"
end


Ast.toS Id("a",Int)

最佳答案

你收到一个错误,因为你没有在函数应用程序中用括号括起你的类型构造函数。但是,您还必须通过定义它们的模块之外的完全限定名称来引用类型构造函数。即

Ast.toS (Ast.Id("a",Typ.Int))

或者,您可以打开模块。但这被认为是不好的做法。即

open Id
open Typ
Ast.toS (Id("a",Int))

关于module - OCaml 此函数应用于太多参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13386652/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com