X-Git-Url: https://git.martlubbers.net/?a=blobdiff_plain;ds=sidebyside;f=Generics%2FgCons.icl;h=62caa2749f42bb323d76a0ee181cdc6c7ef193a8;hb=ff7049a99f7fdd701d49222019df65a9aee8f05a;hp=0552ee27ff7b10d0bbec23713f2e90cc454b3af8;hpb=7d99c50313739f5a435b5cb87a2393ae379ba09f;p=mTask.git diff --git a/Generics/gCons.icl b/Generics/gCons.icl index 0552ee2..62caa27 100644 --- a/Generics/gCons.icl +++ b/Generics/gCons.icl @@ -8,7 +8,14 @@ implementation module Generics.gCons */ import StdEnv, StdGeneric, GenBimap, _SystemStrictLists +import Data.Functor import Data.List +import Data.Maybe + +consByName :: String -> Maybe a | conses{|*|}, consName{|*|} a +consByName a = let cs = conses{|*|} + in ((!!) cs) <$> elemIndex a (map consName{|*|} cs) + generic consName a :: a -> String consName{|CONS of {gcd_name}|} f x = gcd_name @@ -77,14 +84,10 @@ 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 -derive consIndex (),(,),(,,),(,,,),(,,,,),(,,,,,),(,,,,,,),(,,,,,,,),(,,,,,,,,),(,,,,,,,,,),(,,,,,,,,,,),(,,,,,,,,,,,),(,,,,,,,,,,,,),(,,,,,,,,,,,,,),(,,,,,,,,,,,,,,),(,,,,,,,,,,,,,,,),(,,,,,,,,,,,,,,,,),(,,,,,,,,,,,,,,,,,),(,,,,,,,,,,,,,,,,,,),(,,,,,,,,,,,,,,,,,,,),(,,,,,,,,,,,,,,,,,,,,),(,,,,,,,,,,,,,,,,,,,,,),(,,,,,,,,,,,,,,,,,,,,,,),(,,,,,,,,,,,,,,,,,,,,,,,),(,,,,,,,,,,,,,,,,,,,,,,,,),(,,,,,,,,,,,,,,,,,,,,,,,,,),(,,,,,,,,,,,,,,,,,,,,,,,,,,),(,,,,,,,,,,,,,,,,,,,,,,,,,,,),(,,,,,,,,,,,,,,,,,,,,,,,,,,,,),(,,,,,,,,,,,,,,,,,,,,,,,,,,,,,),(,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,) +derive consIndex [],[!],[ !],[!!],(),(,),(,,),(,,,),(,,,,),(,,,,,),(,,,,,,),(,,,,,,,),(,,,,,,,,),(,,,,,,,,,),(,,,,,,,,,,),(,,,,,,,,,,,),(,,,,,,,,,,,,),(,,,,,,,,,,,,,),(,,,,,,,,,,,,,,),(,,,,,,,,,,,,,,,),(,,,,,,,,,,,,,,,,),(,,,,,,,,,,,,,,,,,),(,,,,,,,,,,,,,,,,,,),(,,,,,,,,,,,,,,,,,,,),(,,,,,,,,,,,,,,,,,,,,),(,,,,,,,,,,,,,,,,,,,,,),(,,,,,,,,,,,,,,,,,,,,,,),(,,,,,,,,,,,,,,,,,,,,,,,),(,,,,,,,,,,,,,,,,,,,,,,,,),(,,,,,,,,,,,,,,,,,,,,,,,,,),(,,,,,,,,,,,,,,,,,,,,,,,,,,),(,,,,,,,,,,,,,,,,,,,,,,,,,,,),(,,,,,,,,,,,,,,,,,,,,,,,,,,,,),(,,,,,,,,,,,,,,,,,,,,,,,,,,,,,),(,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,) generic conses a :: [a] conses{|CONS|} f = [CONS (hd f)] @@ -99,11 +102,7 @@ conses{|Bool|} = [True] conses{|Char|} = ['\0'] conses{|Real|} = [0.0] conses{|String|} = [""] -conses{|[]|} _ = [[ ]] -conses{|[!]|} _ = [[!]] -conses{|[ !]|} _ = [[ !]] -conses{|[!!]|} _ = [[!!]] conses{|{}|} _ = [{}] conses{|{!}|} _ = [{!}] conses{|(->)|} _ _ = [const undef] -derive conses (),(,),(,,),(,,,),(,,,,),(,,,,,),(,,,,,,),(,,,,,,,),(,,,,,,,,),(,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