Advertisement
Guest User

Untitled

a guest
Jan 13th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
OCaml 0.88 KB | None | 0 0
  1. module SetRing (F : FiniteRing) : Ring with type t = F.t list = struct
  2.   type t = F.t list
  3.   let zero = []
  4.   let one = F.elems
  5.   let compare a b = let rec innercomp a b = match (a,b) with
  6.    | (x1::xs1, x2::xs2) -> if ((F.compare x1 x2) == 0) then (innercomp xs1 xs2) else F.compare x1 x2
  7.    | (x1::xs1, []) -> 1
  8.    | ([], x2::xs2) -> -1
  9.    | ([], []) -> 0
  10.     in
  11.     innercomp (List.sort F.compare a) (List.sort F.compare b)
  12.  
  13.   let to_string a = let rec inner a = match a with
  14.     | [] -> ""
  15.     | [x] -> F.to_string x
  16.     | x::xs -> F.to_string x ^ "," ^ (inner xs)
  17.     in
  18.     "{" ^ (inner a) ^ "}"
  19.   let rec add a b = let rec inner a = match a with
  20.     | [] -> []
  21.     | x::xs -> if (List.mem x xs) then inner xs else x::(inner xs)
  22.     in
  23.     inner (a @ b)
  24.   let rec mul a b = match a with
  25.     | [] -> []
  26.     | x::xs -> if (List.mem x b) then x::(mul xs b) else mul xs b
  27. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement