File: EnumCyclic.hs

package info (click to toggle)
haskell-derive 2.5.16-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 460 kB
  • sloc: haskell: 3,686; makefile: 5
file content (105 lines) | stat: -rw-r--r-- 5,626 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
module Data.Derive.EnumCyclic where
{-
import Prelude(Enum)

example :: Sample

instance Enum (Sample a) where
    toEnum 0 = First{}
    toEnum 1 = Second{}
    toEnum 2 = Third{}
    toEnum n = error $ "toEnum " ++ show n ++ ", not defined for Sample"

    fromEnum (First{}) = 0
    fromEnum (Second{}) = 1
    fromEnum (Third{}) = 2


    succ a = if b == length [First{},Second{},Third{}] then toEnum 0 else toEnum (b+1)
        where b = fromEnum a

    pred a = if b == 0 then toEnum (length [First{},Second{},Third{}]) else toEnum (b-1)
        where b = fromEnum a

-}
-- GENERATED START

import Data.Derive.DSL.DSL
import Data.Derive.Internal.Derivation

makeEnumCyclic :: Derivation
makeEnumCyclic = derivationDSL "EnumCyclic" dslEnumCyclic

dslEnumCyclic =
    List [Instance [] "Enum" (List [App "InsDecl" (List [App "FunBind"
    (List [Concat (List [MapCtor (App "Match" (List [App "Ident" (List
    [String "toEnum"]),List [App "PLit" (List [App "Int" (List [
    CtorIndex])])],App "Nothing" (List []),App "UnGuardedRhs" (List [
    App "RecConstr" (List [App "UnQual" (List [App "Ident" (List [
    CtorName])]),List []])]),App "BDecls" (List [List []])])),List [
    App "Match" (List [App "Ident" (List [String "toEnum"]),List [App
    "PVar" (List [App "Ident" (List [String "n"])])],App "Nothing" (
    List []),App "UnGuardedRhs" (List [App "InfixApp" (List [App "Var"
    (List [App "UnQual" (List [App "Ident" (List [String "error"])])])
    ,App "QVarOp" (List [App "UnQual" (List [App "Symbol" (List [
    String "$"])])]),Fold (App "InfixApp" (List [Head,App "QVarOp" (
    List [App "UnQual" (List [App "Symbol" (List [String "++"])])]),
    Tail])) (List [App "Lit" (List [App "String" (List [String
    "toEnum "])]),App "App" (List [App "Var" (List [App "UnQual" (List
    [App "Ident" (List [String "show"])])]),App "Var" (List [App
    "UnQual" (List [App "Ident" (List [String "n"])])])]),App "Lit" (
    List [App "String" (List [Concat (List [String
    ", not defined for ",DataName])])])])])]),App "BDecls" (List [List
    []])])]])])]),App "InsDecl" (List [App "FunBind" (List [MapCtor (
    App "Match" (List [App "Ident" (List [String "fromEnum"]),List [
    App "PParen" (List [App "PRec" (List [App "UnQual" (List [App
    "Ident" (List [CtorName])]),List []])])],App "Nothing" (List []),
    App "UnGuardedRhs" (List [App "Lit" (List [App "Int" (List [
    CtorIndex])])]),App "BDecls" (List [List []])]))])]),App "InsDecl"
    (List [App "FunBind" (List [List [App "Match" (List [App "Ident" (
    List [String "succ"]),List [App "PVar" (List [App "Ident" (List [
    String "a"])])],App "Nothing" (List []),App "UnGuardedRhs" (List [
    App "If" (List [App "InfixApp" (List [App "Var" (List [App
    "UnQual" (List [App "Ident" (List [String "b"])])]),App "QVarOp" (
    List [App "UnQual" (List [App "Symbol" (List [String "=="])])]),
    App "App" (List [App "Var" (List [App "UnQual" (List [App "Ident"
    (List [String "length"])])]),App "List" (List [MapCtor (App
    "RecConstr" (List [App "UnQual" (List [App "Ident" (List [CtorName
    ])]),List []]))])])]),App "App" (List [App "Var" (List [App
    "UnQual" (List [App "Ident" (List [String "toEnum"])])]),App "Lit"
    (List [App "Int" (List [Int 0])])]),App "App" (List [App "Var" (
    List [App "UnQual" (List [App "Ident" (List [String "toEnum"])])])
    ,App "Paren" (List [App "InfixApp" (List [App "Var" (List [App
    "UnQual" (List [App "Ident" (List [String "b"])])]),App "QVarOp" (
    List [App "UnQual" (List [App "Symbol" (List [String "+"])])]),App
    "Lit" (List [App "Int" (List [Int 1])])])])])])]),App "BDecls" (
    List [List [App "PatBind" (List [App "PVar" (List [App "Ident" (
    List [String "b"])]),App "Nothing" (List []),App "UnGuardedRhs" (
    List [App "App" (List [App "Var" (List [App "UnQual" (List [App
    "Ident" (List [String "fromEnum"])])]),App "Var" (List [App
    "UnQual" (List [App "Ident" (List [String "a"])])])])]),App
    "BDecls" (List [List []])])]])])]])]),App "InsDecl" (List [App
    "FunBind" (List [List [App "Match" (List [App "Ident" (List [
    String "pred"]),List [App "PVar" (List [App "Ident" (List [String
    "a"])])],App "Nothing" (List []),App "UnGuardedRhs" (List [App
    "If" (List [App "InfixApp" (List [App "Var" (List [App "UnQual" (
    List [App "Ident" (List [String "b"])])]),App "QVarOp" (List [App
    "UnQual" (List [App "Symbol" (List [String "=="])])]),App "Lit" (
    List [App "Int" (List [Int 0])])]),App "App" (List [App "Var" (
    List [App "UnQual" (List [App "Ident" (List [String "toEnum"])])])
    ,App "Paren" (List [App "App" (List [App "Var" (List [App "UnQual"
    (List [App "Ident" (List [String "length"])])]),App "List" (List [
    MapCtor (App "RecConstr" (List [App "UnQual" (List [App "Ident" (
    List [CtorName])]),List []]))])])])]),App "App" (List [App "Var" (
    List [App "UnQual" (List [App "Ident" (List [String "toEnum"])])])
    ,App "Paren" (List [App "InfixApp" (List [App "Var" (List [App
    "UnQual" (List [App "Ident" (List [String "b"])])]),App "QVarOp" (
    List [App "UnQual" (List [App "Symbol" (List [String "-"])])]),App
    "Lit" (List [App "Int" (List [Int 1])])])])])])]),App "BDecls" (
    List [List [App "PatBind" (List [App "PVar" (List [App "Ident" (
    List [String "b"])]),App "Nothing" (List []),App "UnGuardedRhs" (
    List [App "App" (List [App "Var" (List [App "UnQual" (List [App
    "Ident" (List [String "fromEnum"])])]),App "Var" (List [App
    "UnQual" (List [App "Ident" (List [String "a"])])])])]),App
    "BDecls" (List [List []])])]])])]])])])]
-- GENERATED STOP