Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module SetRing (F : FiniteRing) : Ring with type t = F.t list = struct
- type t = F.t list
- let zero = []
- let one = F.elems
- let compare a b = let rec innercomp a b = match (a,b) with
- | (x1::xs1, x2::xs2) -> if ((F.compare x1 x2) == 0) then (innercomp xs1 xs2) else F.compare x1 x2
- | (x1::xs1, []) -> 1
- | ([], x2::xs2) -> -1
- | ([], []) -> 0
- in
- innercomp (List.sort F.compare a) (List.sort F.compare b)
- let to_string a = let rec inner a = match a with
- | [] -> ""
- | [x] -> F.to_string x
- | x::xs -> F.to_string x ^ "," ^ (inner xs)
- in
- "{" ^ (inner a) ^ "}"
- let rec add a b = let rec inner a = match a with
- | [] -> []
- | x::xs -> if (List.mem x xs) then inner xs else x::(inner xs)
- in
- inner (a @ b)
- let rec mul a b = match a with
- | [] -> []
- | x::xs -> if (List.mem x b) then x::(mul xs b) else mul xs b
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement