zipper 0.3 → 0.3.1
raw patch · 3 files changed
+125/−21 lines, 3 filesdep ~multirec
Dependency ranges changed: multirec
Files
- examples/ASTEditor.hs +1/−0
- examples/ASTUse.hs +100/−0
- zipper.cabal +24/−21
examples/ASTEditor.hs view
@@ -1,4 +1,5 @@ {-# LANGUAGE FlexibleContexts #-}+{-# LANGUAGE GADTs #-} module Main where
+ examples/ASTUse.hs view
@@ -0,0 +1,100 @@+{-# LANGUAGE GADTs #-}+{-# LANGUAGE KindSignatures #-}+{-# LANGUAGE MultiParamTypeClasses #-}+{-# LANGUAGE TypeFamilies #-}+{-# LANGUAGE TypeOperators #-}+{-# LANGUAGE TypeSynonymInstances #-}+{-# LANGUAGE EmptyDataDecls #-}++module ASTUse where++import Generics.MultiRec.Base+import AST++-- * Instantiating the library for AST ++-- ** Index type++data AST :: * -> * where+ Expr :: AST Expr+ Decl :: AST Decl+ Var :: AST Var++-- ** Constructors++data Const+instance Constructor Const where conName _ = "Const"+data Add+instance Constructor Add where conName _ = "Add"+data Mul+instance Constructor Mul where conName _ = "Mul"+data EVar+instance Constructor EVar where conName _ = "EVar"+data Let+instance Constructor Let where conName _ = "Let"+data Assign+instance Constructor Assign where+ conName _ = ":="+ conFixity _ = Infix NotAssociative 1+data Seq+instance Constructor Seq where conName _ = "Seq"+data None+instance Constructor None where conName _ = "None"++-- ** Functor encoding++-- Variations of the encoding below are possible. For instance,+-- the 'C' applications can be omitted if no functions that require+-- constructor information are needed. Furthermore, it is possible+-- to tag every constructor rather than every datatype. That makes+-- the overall structure slightly simpler, but makes the nesting+-- of 'L' and 'R' constructors larger in turn.++type instance PF AST = + ( C Const (K Int)+ :+: C Add (I Expr :*: I Expr)+ :+: C Mul (I Expr :*: I Expr)+ :+: C EVar (I Var)+ :+: C Let (I Decl :*: I Expr)+ ) :>: Expr+ :+: ( C Assign (I Var :*: I Expr)+ :+: C Seq (I Decl :*: I Decl)+ :+: C None U+ ) :>: Decl+ :+: ( (K String)+ ) :>: Var++-- ** 'El' instances++instance El AST Expr where proof = Expr+instance El AST Decl where proof = Decl+instance El AST Var where proof = Var++-- ** 'Fam' instance++instance Fam AST where++ from Expr (Const i) = L (Tag (L (C (K i))))+ from Expr (Add e f) = L (Tag (R (L (C (I (I0 e) :*: I (I0 f))))))+ from Expr (Mul e f) = L (Tag (R (R (L (C (I (I0 e) :*: I (I0 f)))))))+ from Expr (EVar x) = L (Tag (R (R (R (L (C (I (I0 x))))))))+ from Expr (Let d e) = L (Tag (R (R (R (R (C (I (I0 d) :*: I (I0 e))))))))++ from Decl (x := e) = R (L (Tag (L (C (I (I0 x) :*: I (I0 e))))))+ from Decl (Seq c d) = R (L (Tag (R (L (C (I (I0 c) :*: I (I0 d)))))))+ from Decl (None) = R (L (Tag (R (R (C U)))))++ from Var x = R (R (Tag (K x)))++ to Expr (L (Tag (L (C (K i))))) = Const i+ to Expr (L (Tag (R (L (C (I (I0 e) :*: I (I0 f))))))) = Add e f+ to Expr (L (Tag (R (R (L (C (I (I0 e) :*: I (I0 f)))))))) = Mul e f+ to Expr (L (Tag (R (R (R (L (C (I (I0 x))))))))) = EVar x+ to Expr (L (Tag (R (R (R (R (C (I (I0 d) :*: I (I0 e))))))))) = Let d e++ to Decl (R (L (Tag (L (C (I (I0 x) :*: I (I0 e))))))) = x := e+ to Decl (R (L (Tag (R (L (C (I (I0 c) :*: I (I0 d)))))))) = Seq c d+ to Decl (R (L (Tag (R (R (C U)))))) = None++ to Var (R (R (Tag (K x)))) = x+
zipper.cabal view
@@ -1,15 +1,15 @@-name: zipper-version: 0.3-license: BSD3-license-file: LICENSE-author: Alexey Rodriguez,+name: zipper+version: 0.3.1+license: BSD3+license-file: LICENSE+author: Alexey Rodriguez, Stefan Holdermans, Andres Löh, Johan Jeuring-maintainer: generics@haskell.org-category: Generics-synopsis: Generic zipper for families of recursive datatypes-homepage: http://www.cs.uu.nl/wiki/GenericProgramming/Multirec+maintainer: generics@haskell.org+category: Generics+synopsis: Generic zipper for families of recursive datatypes+homepage: http://www.cs.uu.nl/wiki/GenericProgramming/Multirec description: The Zipper is a data structure that allows typed navigation on a value. It maintains a subterm as a current point of focus. The rest of the value@@ -23,16 +23,19 @@ so all that is required to get a Zipper for a datatype family is to instantiate the multirec library for that family. -stability: experimental-build-type: Simple-cabal-version: >= 1.2.1-tested-with: GHC == 6.8.3, GHC == 6.10.3-hs-source-dirs: src-exposed-modules: Generics.MultiRec.Zipper+stability: experimental+build-type: Simple+cabal-version: >= 1.2.1+tested-with: GHC == 6.10.4, GHC == 7.0.1+extra-source-files: examples/AST.hs+ examples/ASTUse.hs+ examples/ASTZipper.hs+ examples/ASTEditor.hs+ CREDITS -extra-source-files: examples/AST.hs- examples/ASTZipper.hs- examples/ASTEditor.hs- CREDITS-build-depends: base >= 3 && < 5,- multirec >= 0.4 && < 0.5+library+ hs-source-dirs: src+ exposed-modules: Generics.MultiRec.Zipper++ build-depends: base >= 3 && < 5,+ multirec >= 0.4 && < 0.6