-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from modular-implicits/cleanup
More code cleanup
- Loading branch information
Showing
9 changed files
with
95 additions
and
119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
(library | ||
(public_name generics) | ||
(modules Generic GenShow GenEq Memo GenOrd) | ||
(modules Generic Show Eq Memo Ord) | ||
(libraries imp) | ||
(synopsis "Experimental library using modular implicits")) | ||
(synopsis "Experimental library using modular implicits")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,25 @@ | ||
open Generic;; | ||
open Imp.Data;; | ||
|
||
|
||
|
||
implicit module EqGenBasic {X : Eq} : Eq with type t = X.t genBasic = struct | ||
type t = X.t genBasic | ||
let ( = ) (GenBasic (_, a)) (GenBasic (_, b)) = X.( = ) a b | ||
end;; | ||
open Generic | ||
open Imp.Data | ||
|
||
implicit module EqGenBasic {X : Eq} : Eq with type t = X.t basic = struct | ||
type t = X.t basic | ||
let ( = ) (Basic (_, a)) (Basic (_, b)) = X.( = ) a b | ||
end | ||
|
||
implicit module EqGenProd {X : Eq} {Y : Eq} : Eq with type t = (X.t, Y.t) genProd = struct | ||
type t = (X.t, Y.t) genProd | ||
let ( = ) (GenProd (a1, a2)) (GenProd (b1, b2)) = X.( = ) a1 b1 && Y.( = ) a2 b2 | ||
end;; | ||
implicit module EqGenProd {X : Eq} {Y : Eq} : Eq with type t = (X.t, Y.t) prod = struct | ||
type t = (X.t, Y.t) prod | ||
let ( = ) (Prod (a1, a2)) (Prod (b1, b2)) = X.( = ) a1 b1 && Y.( = ) a2 b2 | ||
end | ||
|
||
implicit module EqGenSum {X : Eq} {Y : Eq} : Eq with type t = (X.t, Y.t) genSum = struct | ||
type t = (X.t, Y.t) genSum | ||
implicit module EqGenSum {X : Eq} {Y : Eq} : Eq with type t = (X.t, Y.t) sum = struct | ||
type t = (X.t, Y.t) sum | ||
let ( = ) a b = match a, b with | ||
| Left a, Left b -> X.( = ) a b | ||
| Right a, Right b -> Y.( = ) a b | ||
| _ -> false | ||
end;; | ||
|
||
end | ||
|
||
implicit module EqGeneric {X : Generic} {XRep : Eq with type t = X.rep} : Eq with type t = X.t = struct | ||
type t = X.t | ||
let ( = ) a b = XRep.(=) (toRep a) (toRep b) | ||
end | ||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,16 @@ | ||
|
||
|
||
module type Generic = sig | ||
type t | ||
type rep | ||
val toRep : t -> rep | ||
val fromRep : rep -> t | ||
end;; | ||
|
||
let toRep {G : Generic} = G.toRep;; | ||
|
||
let fromRep {G : Generic} = G.fromRep;; | ||
|
||
type 'a genBasic = GenBasic of (string * 'a);; | ||
|
||
type ('a, 'b) genProd = GenProd of ('a * 'b );; | ||
|
||
type ('a, 'b) genSum = Left of 'a | Right of 'b;; | ||
|
||
end | ||
|
||
let toRep {G : Generic} = G.toRep | ||
|
||
let fromRep {G : Generic} = G.fromRep | ||
|
||
type 'a basic = Basic of (string * 'a) | ||
|
||
type ('a, 'b) prod = Prod of ('a * 'b ) | ||
|
||
type ('a, 'b) sum = Left of 'a | Right of 'b |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
open Imp.Show | ||
open Generic | ||
|
||
implicit module ShowGenBasic {X : Show} : Show with type t = X.t basic = struct | ||
type t = X.t basic | ||
let show (Basic (s, x)) = s ^ " " ^ X.show x | ||
end | ||
|
||
implicit module ShowGenProd {X : Show} {Y : Show} : Show with type t = (X.t, Y.t) prod = struct | ||
type t = (X.t, Y.t) prod | ||
let show (Prod (x, y)) = X.show x ^ ", " ^ Y.show y | ||
end | ||
|
||
implicit module ShowGenSum {X : Show} {Y : Show} : Show with type t = (X.t, Y.t) sum = struct | ||
type t = (X.t, Y.t) sum | ||
let show = function | ||
| (Left a) -> X.show a | ||
| (Right b) -> Y.show b | ||
end | ||
|
||
implicit module ShowGeneric {X : Generic} {XRep : Show with type t = X.rep} : Show with type t = X.t = struct | ||
type t = X.t | ||
let show x = XRep.show (X.toRep x) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters