From 7d99c50313739f5a435b5cb87a2393ae379ba09f Mon Sep 17 00:00:00 2001 From: Mart Lubbers Date: Sun, 26 Feb 2017 14:00:52 +0100 Subject: [PATCH] extend generics with more tuples --- Generics/gCons.dcl | 6 ++--- Generics/gCons.icl | 55 ++++++++++++++++++++++++++++++++++++---------- 2 files changed, 47 insertions(+), 14 deletions(-) diff --git a/Generics/gCons.dcl b/Generics/gCons.dcl index ad99042..02f182e 100644 --- a/Generics/gCons.dcl +++ b/Generics/gCons.dcl @@ -10,10 +10,10 @@ definition module Generics.gCons import StdGeneric generic consName a :: a -> String -derive consName CONS of {gcd_name},UNIT,PAIR,EITHER,OBJECT,RECORD,FIELD,Int,Bool,Char,String,(),(,),(,,),(,,,),(,,,,),(->),[] +derive consName CONS of {gcd_name},UNIT,PAIR,EITHER,OBJECT,FIELD,RECORD,Int,Bool,Char,Real,String,(),(,),(,,),(,,,),(,,,,),(,,,,,),(,,,,,,),(,,,,,,,),(,,,,,,,,),(,,,,,,,,,),(,,,,,,,,,,),(,,,,,,,,,,,),(,,,,,,,,,,,,),(,,,,,,,,,,,,,),(,,,,,,,,,,,,,,),(,,,,,,,,,,,,,,,),(,,,,,,,,,,,,,,,,),(,,,,,,,,,,,,,,,,,),(,,,,,,,,,,,,,,,,,,),(,,,,,,,,,,,,,,,,,,,),(,,,,,,,,,,,,,,,,,,,,),(,,,,,,,,,,,,,,,,,,,,,),(,,,,,,,,,,,,,,,,,,,,,,),(,,,,,,,,,,,,,,,,,,,,,,,),(,,,,,,,,,,,,,,,,,,,,,,,,),(,,,,,,,,,,,,,,,,,,,,,,,,,),(,,,,,,,,,,,,,,,,,,,,,,,,,,),(,,,,,,,,,,,,,,,,,,,,,,,,,,,),(,,,,,,,,,,,,,,,,,,,,,,,,,,,,),(,,,,,,,,,,,,,,,,,,,,,,,,,,,,,),(,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,),{},{!},[],[! ],[ !],[!!] generic consIndex a :: a -> Int -derive consIndex CONS of {gcd_index},UNIT,PAIR,EITHER,OBJECT,Int,Bool,Char,String,(),(,),(,,),(,,,),(,,,,),[] +derive consIndex CONS of {gcd_index},UNIT,PAIR,EITHER,OBJECT,FIELD,RECORD,Int,Bool,Char,Real,String,(),(,),(,,),(,,,),(,,,,),(,,,,,),(,,,,,,),(,,,,,,,),(,,,,,,,,),(,,,,,,,,,),(,,,,,,,,,,),(,,,,,,,,,,,),(,,,,,,,,,,,,),(,,,,,,,,,,,,,),(,,,,,,,,,,,,,,),(,,,,,,,,,,,,,,,),(,,,,,,,,,,,,,,,,),(,,,,,,,,,,,,,,,,,),(,,,,,,,,,,,,,,,,,,),(,,,,,,,,,,,,,,,,,,,),(,,,,,,,,,,,,,,,,,,,,),(,,,,,,,,,,,,,,,,,,,,,),(,,,,,,,,,,,,,,,,,,,,,,),(,,,,,,,,,,,,,,,,,,,,,,,),(,,,,,,,,,,,,,,,,,,,,,,,,),(,,,,,,,,,,,,,,,,,,,,,,,,,),(,,,,,,,,,,,,,,,,,,,,,,,,,,),(,,,,,,,,,,,,,,,,,,,,,,,,,,,),(,,,,,,,,,,,,,,,,,,,,,,,,,,,,),(,,,,,,,,,,,,,,,,,,,,,,,,,,,,,),(,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,),{},{!},[],[! ],[ !],[!!] generic conses a :: [a] -derive conses CONS,UNIT,PAIR,EITHER,OBJECT,FIELD,RECORD,Int,Bool,Char,Real,String,(),(,),(,,),(,,,),(,,,,),{},{!},[],[! ],[ !],[!!],(->) +derive conses CONS,UNIT,PAIR,EITHER,OBJECT,FIELD,RECORD,Int,Bool,Char,Real,String,(),(,),(,,),(,,,),(,,,,),(,,,,,),(,,,,,,),(,,,,,,,),(,,,,,,,,),(,,,,,,,,,),(,,,,,,,,,,),(,,,,,,,,,,,),(,,,,,,,,,,,,),(,,,,,,,,,,,,,),(,,,,,,,,,,,,,,),(,,,,,,,,,,,,,,,),(,,,,,,,,,,,,,,,,),(,,,,,,,,,,,,,,,,,),(,,,,,,,,,,,,,,,,,,),(,,,,,,,,,,,,,,,,,,,),(,,,,,,,,,,,,,,,,,,,,),(,,,,,,,,,,,,,,,,,,,,,),(,,,,,,,,,,,,,,,,,,,,,,),(,,,,,,,,,,,,,,,,,,,,,,,),(,,,,,,,,,,,,,,,,,,,,,,,,),(,,,,,,,,,,,,,,,,,,,,,,,,,),(,,,,,,,,,,,,,,,,,,,,,,,,,,),(,,,,,,,,,,,,,,,,,,,,,,,,,,,),(,,,,,,,,,,,,,,,,,,,,,,,,,,,,),(,,,,,,,,,,,,,,,,,,,,,,,,,,,,,),(,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,),{},{!},[],[! ],[ !],[!!],(->) diff --git a/Generics/gCons.icl b/Generics/gCons.icl index 6f0ceb3..0552ee2 100644 --- a/Generics/gCons.icl +++ b/Generics/gCons.icl @@ -22,14 +22,46 @@ consName{|FIELD|} f (FIELD x) = f x consName{|Int|} i = toString i consName{|Bool|} b = toString b consName{|Char|} c = toString c +consName{|Real|} r = toString r consName{|String|} s = s consName{|[]|} _ _ = "[]" +consName{|[!]|} _ _ = "[!]" +consName{|[ !]|} _ _ = "[ !]" +consName{|[!!]|} _ _ = "[!!]" +consName{|{}|} _ _ = "{}" +consName{|{!}|} _ _ = "{!}" +consName{|(->)|} f g x = g (x undef) consName{|()|} _ = "()" consName{|(,)|} _ _ _ = "(,)" consName{|(,,)|} _ _ _ _ = "(,,)" consName{|(,,,)|} _ _ _ _ _ = "(,,,)" consName{|(,,,,)|} _ _ _ _ _ _ = "(,,,,)" -consName{|(->)|} f g x = g (x undef) +consName{|(,,,,,)|} _ _ _ _ _ _ _ = "(,,,,,)" +consName{|(,,,,,,)|} _ _ _ _ _ _ _ _ = "(,,,,,,)" +consName{|(,,,,,,,)|} _ _ _ _ _ _ _ _ _ = "(,,,,,,,)" +consName{|(,,,,,,,,)|} _ _ _ _ _ _ _ _ _ _ = "(,,,,,,,,)" +consName{|(,,,,,,,,,)|} _ _ _ _ _ _ _ _ _ _ _ = "(,,,,,,,,,)" +consName{|(,,,,,,,,,,)|} _ _ _ _ _ _ _ _ _ _ _ _ = "(,,,,,,,,,,)" +consName{|(,,,,,,,,,,,)|} _ _ _ _ _ _ _ _ _ _ _ _ _ = "(,,,,,,,,,,,)" +consName{|(,,,,,,,,,,,,)|} _ _ _ _ _ _ _ _ _ _ _ _ _ _ = "(,,,,,,,,,,,,)" +consName{|(,,,,,,,,,,,,,)|} _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ = "(,,,,,,,,,,,,,)" +consName{|(,,,,,,,,,,,,,,)|} _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ = "(,,,,,,,,,,,,,,)" +consName{|(,,,,,,,,,,,,,,,)|} _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ = "(,,,,,,,,,,,,,,,)" +consName{|(,,,,,,,,,,,,,,,,)|} _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ = "(,,,,,,,,,,,,,,,,)" +consName{|(,,,,,,,,,,,,,,,,,)|} _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ = "(,,,,,,,,,,,,,,,,,)" +consName{|(,,,,,,,,,,,,,,,,,,)|} _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ = "(,,,,,,,,,,,,,,,,,,)" +consName{|(,,,,,,,,,,,,,,,,,,,)|} _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ = "(,,,,,,,,,,,,,,,,,,,)" +consName{|(,,,,,,,,,,,,,,,,,,,,)|} _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ = "(,,,,,,,,,,,,,,,,,,,,)" +consName{|(,,,,,,,,,,,,,,,,,,,,,)|} _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ = "(,,,,,,,,,,,,,,,,,,,,,)" +consName{|(,,,,,,,,,,,,,,,,,,,,,,)|} _ _ _ _ _ _ _ _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,,,,,,,,,,,,,,,,,,,,,,,,,,)" generic consIndex a :: a -> Int consIndex{|CONS of {gcd_index}|} f x = gcd_index @@ -38,16 +70,21 @@ consIndex{|PAIR|} f g (PAIR x y) = f x consIndex{|EITHER|} f g (LEFT x) = f x consIndex{|EITHER|} f g (RIGHT y) = g y consIndex{|OBJECT|} f (OBJECT x) = f x +consIndex{|RECORD|} f (RECORD x) = f x +consIndex{|FIELD|} f (FIELD x) = f x consIndex{|Int|} i = i consIndex{|Bool|} b = if b 1 0 consIndex{|Char|} c = toInt c +consIndex{|Real|} r = toInt r consIndex{|String|} _ = 0 consIndex{|[]|} _ _ = 0 -consIndex{|()|} _ = 0 -consIndex{|(,)|} _ _ _ = 0 -consIndex{|(,,)|} _ _ _ _ = 0 -consIndex{|(,,,)|} _ _ _ _ _ = 0 -consIndex{|(,,,,)|} _ _ _ _ _ _ = 0 +consIndex{|[!]|} _ _ = 0 +consIndex{|[ !]|} _ _ = 0 +consIndex{|[!!]|} _ _ = 0 +consIndex{|{}|} _ _ = 0 +consIndex{|{!}|} _ _ = 0 +consIndex{|(->)|} _ _ _ = 0 +derive consIndex (),(,),(,,),(,,,),(,,,,),(,,,,,),(,,,,,,),(,,,,,,,),(,,,,,,,,),(,,,,,,,,,),(,,,,,,,,,,),(,,,,,,,,,,,),(,,,,,,,,,,,,),(,,,,,,,,,,,,,),(,,,,,,,,,,,,,,),(,,,,,,,,,,,,,,,),(,,,,,,,,,,,,,,,,),(,,,,,,,,,,,,,,,,,),(,,,,,,,,,,,,,,,,,,),(,,,,,,,,,,,,,,,,,,,),(,,,,,,,,,,,,,,,,,,,,),(,,,,,,,,,,,,,,,,,,,,,),(,,,,,,,,,,,,,,,,,,,,,,),(,,,,,,,,,,,,,,,,,,,,,,,),(,,,,,,,,,,,,,,,,,,,,,,,,),(,,,,,,,,,,,,,,,,,,,,,,,,,),(,,,,,,,,,,,,,,,,,,,,,,,,,,),(,,,,,,,,,,,,,,,,,,,,,,,,,,,),(,,,,,,,,,,,,,,,,,,,,,,,,,,,,),(,,,,,,,,,,,,,,,,,,,,,,,,,,,,,),(,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,) generic conses a :: [a] conses{|CONS|} f = [CONS (hd f)] @@ -66,11 +103,7 @@ conses{|[]|} _ = [[ ]] conses{|[!]|} _ = [[!]] conses{|[ !]|} _ = [[ !]] conses{|[!!]|} _ = [[!!]] -conses{|()|} = [()] -conses{|(,)|} f g = zip2 f g -conses{|(,,)|} f g h = zip3 f g h -conses{|(,,,)|} f g h i = zip4 f g h i -conses{|(,,,,)|} f g h i j = zip5 f g h i j conses{|{}|} _ = [{}] conses{|{!}|} _ = [{!}] conses{|(->)|} _ _ = [const undef] +derive conses (),(,),(,,),(,,,),(,,,,),(,,,,,),(,,,,,,),(,,,,,,,),(,,,,,,,,),(,,,,,,,,,),(,,,,,,,,,,),(,,,,,,,,,,,),(,,,,,,,,,,,,),(,,,,,,,,,,,,,),(,,,,,,,,,,,,,,),(,,,,,,,,,,,,,,,),(,,,,,,,,,,,,,,,,),(,,,,,,,,,,,,,,,,,),(,,,,,,,,,,,,,,,,,,),(,,,,,,,,,,,,,,,,,,,),(,,,,,,,,,,,,,,,,,,,,),(,,,,,,,,,,,,,,,,,,,,,),(,,,,,,,,,,,,,,,,,,,,,,),(,,,,,,,,,,,,,,,,,,,,,,,),(,,,,,,,,,,,,,,,,,,,,,,,,),(,,,,,,,,,,,,,,,,,,,,,,,,,),(,,,,,,,,,,,,,,,,,,,,,,,,,,),(,,,,,,,,,,,,,,,,,,,,,,,,,,,),(,,,,,,,,,,,,,,,,,,,,,,,,,,,,),(,,,,,,,,,,,,,,,,,,,,,,,,,,,,,),(,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,) -- 2.20.1