我想將此ML代碼翻譯成F#。 fun take ([], i) = []
| take (x::xs, i) = if i > 0 then x::take(xs, i-1)
else [];
我想這一個 let rec take n i =
match n,i with
| [], i -> []
| x::xs, i -> i
我正在閱讀在線書籍「計算分類理論」http://www.cs.man.ac.uk/~david/categories/book/book.pdf,本書中存在問題2.10的一些問題。特別是隨着powerset的定義。 abstype 'a Set = set of 'a list
with val emptyset = set([])
fun is_empty(set(s)) =
Here是完整的規則,但作爲一個簡單的例子,如果A與'a list list list類型和f與'a list -> 'b類型的功能的3D陣列,我想的函數map'這需要升降機f鍵入'a list list list -> 'b list list。對於具體的例子,map'將相當於該代碼: fun map' fList aListListList = map (fn aListList => map
exception div;
fun f(x,y) =
let
val before = 2.0 * x + 3.0 * y
in
(before + (1.0/(if x > 0.0001 then x else raise div)) + 2.0/y) handle div => before/6.0
end
此代碼會產生一些編譯錯誤
我是一個newby。我寫下面的代碼。 Delay(e) == fn() => e
Force(e) == e()
fun time_consuming(n) =
let fun tak(x, y, z) = if x <= y then y
else tak(tak(x-1,y,z), tak(y-1,z,x), tak(z-1,x,y))
in
f
我們接下來dayatype: 和兩個功能: - val real =
fn (Rec(x,y)) => x
| (Polar(r,a)) => r * Math.cos(a);
val real = fn : complex -> real
- val imaginary =
fn (Rec(x,y)) => y
| (Polar(r,a)) => r * Math.sin(