Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
13 changed files
with
5,685 additions
and
5,685 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
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,46 +1,46 @@ | ||
[] and Maybe tests: | ||
- "[1,2,3,4,5,6,7,8,9,10]" | ||
- "[]" | ||
- "\"abc\"" | ||
- "[1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10]" | ||
- "True" | ||
- "False" | ||
- "[Nothing,Just 0,Just -1,Just 1,Just -2]" | ||
- "[[],[0],[0,0],[-1],[0,0,0],[-1,0],[1],[0,-1],[-1,0,0],[1,0],[-2],[0,0,0,0],[-1,-1],[1,0,0],[-2,0]]" | ||
- "[[0],[0,0],[-1],[0,0,0],[-1,0]]" | ||
- "False" | ||
Tests for Tree: | ||
- "Branch 2 Empty (Branch 1 Empty Empty)" | ||
- "[Empty,Branch 1 Empty Empty]" | ||
- "Branch 2 Empty (Branch 1 (Branch 0 Empty Empty) (Branch 0 Empty Empty))" | ||
- "Branch 2 (Branch 1 Empty Empty) Empty" | ||
- "Branch 3 (Branch 0 Empty Empty) (Branch 2 (Branch 0 Empty Empty) (Branch 0 Empty Empty))" | ||
- "[Empty,Branch 0 Empty Empty,Branch 0 Empty (Branch 0 Empty Empty),Branch -1 Empty Empty,Branch 0 (Branch 0 Empty Empty) Empty,Branch -1 Empty (Branch 0 Empty Empty),Branch 1 Empty Empty,Branch 0 Empty (Branch 0 Empty (Branch 0 Empty Empty)),Branch -1 (Branch 0 Empty Empty) Empty,Branch 1 Empty (Branch 0 Empty Empty)]" | ||
Tests for List: | ||
- "Cons 112 (Cons 113 Nil)" | ||
- "Cons \"Cons 'p' (Cons 'q' Nil)\" (Cons \"Nil\" Nil)" | ||
- "Cons 'p' (Cons 'q' Nil)" | ||
- "Cons (Cons 'p' (Cons 'q' Nil)) (Cons Nil Nil)" | ||
- "[Cons 'q' Nil]" | ||
- "[Cons Nil Nil]" | ||
Tests for Rose: | ||
- "Rose [1,2] [Rose [3,4] [],Rose [5] []]" | ||
- "Rose [\"1\",\"2\"] [Rose [\"3\",\"4\"] [],Rose [\"5\"] []]" | ||
Tests for GRose: | ||
- "GRose [1,2] [GRose [3] [],GRose [] []]" | ||
- "GRose [\"1\",\"2\"] [GRose [\"3\"] [],GRose [] []]" | ||
Tests for Either: | ||
- "'p'" | ||
- "\"'p'\"" | ||
Tests for Nested: | ||
- "Nested {value = 1, rec = Nested {value = [2], rec = Nested {value = [[3],[4,5],[]], rec = Leaf}}}" | ||
- "Nested {value = \"1\", rec = Nested {value = [\"2\"], rec = Nested {value = [[\"3\"],[\"4\",\"5\"],[]], rec = Leaf}}}" | ||
Tests for Bush: | ||
- "BushCons 0 (BushCons (BushCons 1 BushNil) BushNil)" | ||
- "BushCons \"0\" (BushCons (BushCons \"1\" BushNil) BushNil)" | ||
[] and Maybe tests: | ||
- "[1,2,3,4,5,6,7,8,9,10]" | ||
- "[]" | ||
- "\"abc\"" | ||
- "[1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10]" | ||
- "True" | ||
- "False" | ||
- "[Nothing,Just 0,Just -1,Just 1,Just -2]" | ||
- "[[],[0],[0,0],[-1],[0,0,0],[-1,0],[1],[0,-1],[-1,0,0],[1,0],[-2],[0,0,0,0],[-1,-1],[1,0,0],[-2,0]]" | ||
- "[[0],[0,0],[-1],[0,0,0],[-1,0]]" | ||
- "False" | ||
Tests for Tree: | ||
- "Branch 2 Empty (Branch 1 Empty Empty)" | ||
- "[Empty,Branch 1 Empty Empty]" | ||
- "Branch 2 Empty (Branch 1 (Branch 0 Empty Empty) (Branch 0 Empty Empty))" | ||
- "Branch 2 (Branch 1 Empty Empty) Empty" | ||
- "Branch 3 (Branch 0 Empty Empty) (Branch 2 (Branch 0 Empty Empty) (Branch 0 Empty Empty))" | ||
- "[Empty,Branch 0 Empty Empty,Branch 0 Empty (Branch 0 Empty Empty),Branch -1 Empty Empty,Branch 0 (Branch 0 Empty Empty) Empty,Branch -1 Empty (Branch 0 Empty Empty),Branch 1 Empty Empty,Branch 0 Empty (Branch 0 Empty (Branch 0 Empty Empty)),Branch -1 (Branch 0 Empty Empty) Empty,Branch 1 Empty (Branch 0 Empty Empty)]" | ||
|
||
Tests for List: | ||
- "Cons 112 (Cons 113 Nil)" | ||
- "Cons \"Cons 'p' (Cons 'q' Nil)\" (Cons \"Nil\" Nil)" | ||
- "Cons 'p' (Cons 'q' Nil)" | ||
- "Cons (Cons 'p' (Cons 'q' Nil)) (Cons Nil Nil)" | ||
- "[Cons 'q' Nil]" | ||
- "[Cons Nil Nil]" | ||
|
||
Tests for Rose: | ||
- "Rose [1,2] [Rose [3,4] [],Rose [5] []]" | ||
- "Rose [\"1\",\"2\"] [Rose [\"3\",\"4\"] [],Rose [\"5\"] []]" | ||
|
||
Tests for GRose: | ||
- "GRose [1,2] [GRose [3] [],GRose [] []]" | ||
- "GRose [\"1\",\"2\"] [GRose [\"3\"] [],GRose [] []]" | ||
|
||
Tests for Either: | ||
- "'p'" | ||
- "\"'p'\"" | ||
|
||
Tests for Nested: | ||
- "Nested {value = 1, rec = Nested {value = [2], rec = Nested {value = [[3],[4,5],[]], rec = Leaf}}}" | ||
- "Nested {value = \"1\", rec = Nested {value = [\"2\"], rec = Nested {value = [[\"3\"],[\"4\",\"5\"],[]], rec = Leaf}}}" | ||
|
||
Tests for Bush: | ||
- "BushCons 0 (BushCons (BushCons 1 BushNil) BushNil)" | ||
- "BushCons \"0\" (BushCons (BushCons \"1\" BushNil) BushNil)" |
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,103 +1,103 @@ | ||
|
||
module Main where | ||
|
||
import Data.List (intersperse) | ||
import System.Environment (getArgs) | ||
|
||
|
||
-------------------------------------------------------------------------------- | ||
-- Tuples | ||
-------------------------------------------------------------------------------- | ||
|
||
u, tab, newline, sp :: ShowS | ||
u = showChar '_' | ||
tab = showString " " | ||
newline = showChar '\n' | ||
sp = showChar ' ' | ||
vars :: [ShowS] | ||
vars = map ((showChar 'x' .) . shows) [1..] | ||
paren :: ShowS -> ShowS | ||
paren x = showChar '(' . x . showChar ')' | ||
concatS :: [ShowS] -> ShowS | ||
concatS = foldr (.) id | ||
|
||
tuple :: Int -> ShowS | ||
tuple m = showChar '(' . showString (replicate (m-1) ',') . showChar ')' | ||
|
||
unlinesS :: [ShowS] -> ShowS | ||
unlinesS = foldr1 (\a b -> a . newline . b) | ||
|
||
createDataDecls :: Int -> ShowS | ||
createDataDecls m = let n = shows m | ||
s = showString "data Tuple" | ||
in s . n . u . newline . s . n . showChar 'C' . u | ||
|
||
dataInstance :: Int -> ShowS | ||
dataInstance m = let n = shows m | ||
l1 = showString "instance Datatype Tuple" | ||
. n . u . showString " where" | ||
l2 = tab . showString "datatypeName _ = \"" | ||
. tuple m . showChar '"' | ||
l3 = tab . showString "moduleName _ = \"Prelude\"" | ||
in unlinesS [l1, l2, l3] | ||
|
||
conInstance :: Int -> ShowS | ||
conInstance m = let n = shows m | ||
in showString "instance Constructor Tuple" . n . u | ||
. showString " where conName _ = \"" . tuple m . showChar '"' | ||
|
||
-- x is 0 or 1 | ||
pairPat, repName, rep, repInst, funs :: Int -> Int -> ShowS | ||
pairPat x m = tuple m . sp . | ||
(concatS $ intersperse sp (take (m - x) vars)) | ||
|
||
repName x m = showString "Rep" . shows x . showString "Tuple" . shows m . u | ||
|
||
rep x m = let n = shows m | ||
v = take (m - x) vars | ||
vs = concatS $ intersperse sp v | ||
recs = concatS $ intersperse (showString " :*: ") $ | ||
map (showString "Rec0 " .) v | ||
last = showString $ if (x == 1) then " :*: Par1" else "" | ||
body = recs . last | ||
in showString "type " . repName x m . sp . vs | ||
. showString " = D1 Tuple" . n . showString "_ (C1 Tuple" . n | ||
. showString "C_ (S1 NoSelector (" . body . showString ")))" | ||
|
||
repInst x m = let n = shows m | ||
y = shows x | ||
vs = concatS $ intersperse sp (take (m - x) vars) | ||
in showString "instance Representable" . y . sp | ||
. paren (pairPat x m) . showString " (" . repName x m . sp | ||
. vs . showString ") where" | ||
. newline . funs x m | ||
|
||
funs x m = | ||
let v = take (m - x) vars | ||
recs = concatS $ intersperse (showString " :*: ") $ | ||
map (showString "K1 " .) v | ||
last = if (x == 1) then showString " :*: Par1 " . (vars !! (m-x)) | ||
else showString "" | ||
eq = showChar '=' | ||
body = paren (showString "M1 (M1 (M1 (" . recs . last . showString ")))") | ||
pat = paren (pairPat 0 m) | ||
in tab . concatS (intersperse sp [showString "from" . shows x, pat, eq, body]) | ||
. newline . | ||
tab . concatS (intersperse sp [showString "to" . shows x, body, eq, pat]) | ||
|
||
|
||
gen :: Int -> ShowS | ||
gen m = concatS (intersperse (newline . newline) | ||
[ createDataDecls m, dataInstance m, conInstance m | ||
, rep 0 m, repInst 0 m, rep 1 m, repInst 1 m]) | ||
|
||
main :: IO () | ||
main = do let r :: [String] -> Int | ||
r (n:_) = read n | ||
r _ = error "Integer argument missing" | ||
com = showString "\n\n" | ||
. concatS (map showChar (replicate 80 '-')) | ||
. showString "\n\n" | ||
a <- getArgs | ||
(putStr . ($ "")) $ concatS $ | ||
intersperse com [ gen m | m <- [2..(r a)]] | ||
|
||
module Main where | ||
|
||
import Data.List (intersperse) | ||
import System.Environment (getArgs) | ||
|
||
|
||
-------------------------------------------------------------------------------- | ||
-- Tuples | ||
-------------------------------------------------------------------------------- | ||
|
||
u, tab, newline, sp :: ShowS | ||
u = showChar '_' | ||
tab = showString " " | ||
newline = showChar '\n' | ||
sp = showChar ' ' | ||
vars :: [ShowS] | ||
vars = map ((showChar 'x' .) . shows) [1..] | ||
paren :: ShowS -> ShowS | ||
paren x = showChar '(' . x . showChar ')' | ||
concatS :: [ShowS] -> ShowS | ||
concatS = foldr (.) id | ||
|
||
tuple :: Int -> ShowS | ||
tuple m = showChar '(' . showString (replicate (m-1) ',') . showChar ')' | ||
|
||
unlinesS :: [ShowS] -> ShowS | ||
unlinesS = foldr1 (\a b -> a . newline . b) | ||
|
||
createDataDecls :: Int -> ShowS | ||
createDataDecls m = let n = shows m | ||
s = showString "data Tuple" | ||
in s . n . u . newline . s . n . showChar 'C' . u | ||
|
||
dataInstance :: Int -> ShowS | ||
dataInstance m = let n = shows m | ||
l1 = showString "instance Datatype Tuple" | ||
. n . u . showString " where" | ||
l2 = tab . showString "datatypeName _ = \"" | ||
. tuple m . showChar '"' | ||
l3 = tab . showString "moduleName _ = \"Prelude\"" | ||
in unlinesS [l1, l2, l3] | ||
|
||
conInstance :: Int -> ShowS | ||
conInstance m = let n = shows m | ||
in showString "instance Constructor Tuple" . n . u | ||
. showString " where conName _ = \"" . tuple m . showChar '"' | ||
|
||
-- x is 0 or 1 | ||
pairPat, repName, rep, repInst, funs :: Int -> Int -> ShowS | ||
pairPat x m = tuple m . sp . | ||
(concatS $ intersperse sp (take (m - x) vars)) | ||
|
||
repName x m = showString "Rep" . shows x . showString "Tuple" . shows m . u | ||
|
||
rep x m = let n = shows m | ||
v = take (m - x) vars | ||
vs = concatS $ intersperse sp v | ||
recs = concatS $ intersperse (showString " :*: ") $ | ||
map (showString "Rec0 " .) v | ||
last = showString $ if (x == 1) then " :*: Par1" else "" | ||
body = recs . last | ||
in showString "type " . repName x m . sp . vs | ||
. showString " = D1 Tuple" . n . showString "_ (C1 Tuple" . n | ||
. showString "C_ (S1 NoSelector (" . body . showString ")))" | ||
|
||
repInst x m = let n = shows m | ||
y = shows x | ||
vs = concatS $ intersperse sp (take (m - x) vars) | ||
in showString "instance Representable" . y . sp | ||
. paren (pairPat x m) . showString " (" . repName x m . sp | ||
. vs . showString ") where" | ||
. newline . funs x m | ||
|
||
funs x m = | ||
let v = take (m - x) vars | ||
recs = concatS $ intersperse (showString " :*: ") $ | ||
map (showString "K1 " .) v | ||
last = if (x == 1) then showString " :*: Par1 " . (vars !! (m-x)) | ||
else showString "" | ||
eq = showChar '=' | ||
body = paren (showString "M1 (M1 (M1 (" . recs . last . showString ")))") | ||
pat = paren (pairPat 0 m) | ||
in tab . concatS (intersperse sp [showString "from" . shows x, pat, eq, body]) | ||
. newline . | ||
tab . concatS (intersperse sp [showString "to" . shows x, body, eq, pat]) | ||
|
||
|
||
gen :: Int -> ShowS | ||
gen m = concatS (intersperse (newline . newline) | ||
[ createDataDecls m, dataInstance m, conInstance m | ||
, rep 0 m, repInst 0 m, rep 1 m, repInst 1 m]) | ||
|
||
main :: IO () | ||
main = do let r :: [String] -> Int | ||
r (n:_) = read n | ||
r _ = error "Integer argument missing" | ||
com = showString "\n\n" | ||
. concatS (map showChar (replicate 80 '-')) | ||
. showString "\n\n" | ||
a <- getArgs | ||
(putStr . ($ "")) $ concatS $ | ||
intersperse com [ gen m | m <- [2..(r a)]] |
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,22 +1,22 @@ | ||
|
||
module Generics.Deriving ( | ||
|
||
module Generics.Deriving.Base, | ||
module Generics.Deriving.Copoint, | ||
module Generics.Deriving.ConNames, | ||
module Generics.Deriving.Enum, | ||
module Generics.Deriving.Eq, | ||
module Generics.Deriving.Functor, | ||
module Generics.Deriving.Show, | ||
module Generics.Deriving.Uniplate | ||
) where | ||
|
||
import Generics.Deriving.Base | ||
import Generics.Deriving.Copoint | ||
import Generics.Deriving.ConNames | ||
import Generics.Deriving.Enum | ||
import Generics.Deriving.Eq | ||
import Generics.Deriving.Functor | ||
import Generics.Deriving.Show | ||
import Generics.Deriving.Uniplate | ||
|
||
module Generics.Deriving ( | ||
|
||
module Generics.Deriving.Base, | ||
module Generics.Deriving.Copoint, | ||
module Generics.Deriving.ConNames, | ||
module Generics.Deriving.Enum, | ||
module Generics.Deriving.Eq, | ||
module Generics.Deriving.Functor, | ||
module Generics.Deriving.Show, | ||
module Generics.Deriving.Uniplate | ||
|
||
) where | ||
|
||
import Generics.Deriving.Base | ||
import Generics.Deriving.Copoint | ||
import Generics.Deriving.ConNames | ||
import Generics.Deriving.Enum | ||
import Generics.Deriving.Eq | ||
import Generics.Deriving.Functor | ||
import Generics.Deriving.Show | ||
import Generics.Deriving.Uniplate |
Oops, something went wrong.