关于如何让两个方法相互呼叫(即有A()呼叫B()和B()呼叫A()),我有点困惑.似乎F#只在代码中遇到它后"看到"该方法,所以如果它没有,它只是说值或构造函数尚未定义.
我错过了一些非常基本的东西吗?
我有一些扩展常见类型的类型,这些是我的模型.
然后我为CRUD操作的每个模型类型都有DAO类型.
我现在需要一个允许我在给定任何模型类型的情况下找到id的函数,因此我为一些其他函数创建了一个新类型.
问题是我不知道如何订购这些类型.目前我在dao之前有模型,但我不知何故需要DAOMisc之前CityDAO和CityDAO之前DAOMisc,这是不可能的.
简单的方法是把每个DAO此功能,指的只是前,可以来的类型,所以,State之前谈到City的State有一个外键关系City,所以辅助功能将是非常短的.但是,这只是让我觉得错误,所以我不确定如何最好地解决这个问题.
这是我的杂项类型,BaseType我的所有模型的常见类型.
type DAOMisc =
member internal self.FindIdByType item =
match(item:BaseType) with
| :? StateType as i ->
let a = (StateDAO()).Retrieve i
a.Head.Id
| :? CityType as i ->
let a = (CityDAO()).Retrieve i
a.Head.Id
| _ -> -1
Run Code Online (Sandbox Code Playgroud)
这是一种dao类型.CommonDAO实际上有CRUD操作的代码,但这在这里并不重要.
type CityDAO() =
inherit CommonDAO<CityType>("city", ["name"; "state_id"],
(fun(reader) ->
[
while reader.Read() do
let s …Run Code Online (Sandbox Code Playgroud) 可能重复:
[F#]如何让两种方法相互呼叫?
大家好,
我有一个场景,我有两个功能,可以从相互递归中受益,但我不确定如何在F#中做到这一点
我的场景不像下面的代码那么简单,但我想得到类似于编译的东西:
let rec f x =
if x>0 then
g (x-1)
else
x
let rec g x =
if x>0 then
f (x-1)
else
x
Run Code Online (Sandbox Code Playgroud) 有没有办法在OCaml中进行C风格的前向声明?
我的问题是我有两个互相引用的变体:
type path_formula =
[ `Next of state_formula
| `Until of (state_formula * state_formula)
| `UntilB of (state_formula * int * state_formula)
]
type state_formula =
[ `True | `False
| `Not of state_formula
| `And of (state_formula * state_formula)
| `Or of (state_formula * state_formula)
| `Imply of (state_formula * state_formula)
| `Label of string
| `Prob` of (boundf * path_formula)
| `Expc` of (boundi * formula)
]
Run Code Online (Sandbox Code Playgroud)
所以这两种类型都必须知道另一种类型..我在Google上搜索它但不幸的是OCaml不是那么广泛使用的编程语言.
我有两个类定义如下:
type foo () =
let getBar() =
new bar()
type bar () =
let getFoo() =
new foo()
Run Code Online (Sandbox Code Playgroud)
编译器说
The type 'bar' is not defined
Run Code Online (Sandbox Code Playgroud)
有没有办法做到这一点?
我对F#很新,所以请不要怪我:)
我的服务给了我用户,组和其他对象.userobject看起来像这样:
{
"id": 0,
"firstname": null,
"lastame": null,
"emailaddress": null,
"active": false,
"groups": null,
"groupcount": 0,
"createdgroups": null,
"createdgroupscount": 0,
"createdfiles": null,
"createdfilescount": 0,
"createdfolders": null,
"createdfolderscount": 0,
"createdvideos": null,
"createdvideoscount": 0,
"createdcategories": null,
"createdcategoriescount": 0
}
Run Code Online (Sandbox Code Playgroud)
组对象如下所示:
{
"id": 0,
"name": null,
"description": null,
"videos": null,
"videocount": 0,
"files": null,
"filecount": 0,
"members": null,
"membercount": 0,
"creator": {
"id": 0,
"firstname": null,
"lastame": null,
"emailaddress": null,
"active": false,
"groups": null,
"groupcount": 0,
"createdgroups": null,
"createdgroupscount": 0,
"createdfiles": null, …Run Code Online (Sandbox Code Playgroud) 我希望有一个类型A,它有一个属性是类型B的实例.类型B有一个类型为A的实例的属性.问题是,F#按顺序读取源文件.因此,如果我首先定义类型A,那么它将无法识别类型B.如果我首先定义类型B,我不能使它具有A的实例.有没有解决方法,或者这只是糟糕的设计对我而言?