関数型言語ML (SML, OCaml, etc.), Part 8 (20レス)
関数型言語ML (SML, OCaml, etc.), Part 8 http://mevius.5ch.net/test/read.cgi/tech/1730427497/
上
下
前
次
1-
新
通常表示
512バイト分割
レス栞
6: デフォルトの名無しさん [] 2024/11/17(日) 22:38:39.01 ID:vlQbYPk+ ◎Haskellで関数の定義いろいろ factorial n = if n = 0 then 1 else n * factorial (n - 1) ◎ガード factorial n | n == 0 = 1 | otherwise = n * factorial (n - 1) ◎foldl factorial n = foldl (*) 1 [1..n] ◎product = foldl (*) 1 factorial n = product [1..n] ◎ラムダ関数として factorial = \n -> if n = 0 then 1 else n * factorial (n - 1) ◎末尾再帰(空白が全部1個になるので_に置き換えてます) factorial = f 1 ___where ______f a 0 = a ______f a x = f (a * x) (x - 1) http://mevius.5ch.net/test/read.cgi/tech/1730427497/6
メモ帳
(0/65535文字)
上
下
前
次
1-
新
書
関
写
板
覧
索
設
栞
歴
あと 14 レスあります
スレ情報
赤レス抽出
画像レス抽出
歴の未読スレ
AAサムネイル
Google検索
Wikipedia
ぬこの手
ぬこTOP
0.272s*