ソースを参照

add basic readme

Mistivia 4 ヶ月 前
コミット
4f1c9f2270
1 ファイル変更31 行追加0 行削除
  1. 31 0
      README.md

+ 31 - 0
README.md

@@ -0,0 +1,31 @@
+# Trait
+
+A trait/typeclass system for Scheme.
+
+## Example
+
+    (import trait)
+	
+	(define-record point x y)
+    
+    (define-trait Eq
+      ;; fallback to equal? by default
+      (same? equal?))
+
+    (define-trait-impl (Eq number?)
+      (same? =))
+    
+    (define-trait-impl (Eq symbol?)
+      (same? eq?))
+	
+	(define-trait-impl (Eq point?)
+	  (same? (lambda (a b) (and (point? b)
+	                            (= (point-x a) (point-x b))
+	                            (= (point-y a) (point-y b))))))
+    
+    (display (list (same? 'a 'a)
+                   (same? 1 1)
+                   (same? 1 2)
+                   (same? (list 1 2) (list 1 2))
+                   (same? (cons 3 4) (cons 3 4))
+				   (same? (make-point 1 2) (make-point 3 4))))