Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
何をやりたいか分からなくなってきたので放流する
let rec factorial n =
match n with
| 0 | 1 -> 1
| _ -> n * (factorial (n - 1))
type FactorialNumber(num: int) =
let infactorials = Seq.initInfinite <| fun i -> factorial (i+1)
let range = Seq.takeWhile (fun fc -> fc <= num) infactorials |> Seq.toList
let rec factSystemize n fcs acc =
match fcs with
| fc::rest ->
let quotient = n / fc
let remainder = n % fc
factSystemize remainder rest (quotient::acc)
| [] -> acc
member val Value = num with get
member val Factorials = factSystemize num (List.rev range) [] with get
member self.Add (other:FactorialNumber) = FactorialNumber(self.Value + other.Value)
static member (+) (self: FactorialNumber, other: FactorialNumber) = self.Add(other)
type FactorialNumberSystemBuilder() =
member __.Run(fn: FactorialNumber) = fn.Factorials
member __.Return(x) = FactorialNumber(x)
member __.Bind(x: FactorialNumber, f) = f (x.Value)
let fns = FactorialNumberSystemBuilder()
fns {
let x = 10
let y = 17
return x + y
} // [1; 1; 0; 1]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.