Safe Haskell | None |
---|---|
Language | Haskell2010 |
Synopsis
- class Letable letName repr where
- class MakeLetName letName where
- makeLetName :: SharingName -> IO letName
- class ShowLetName (showName :: Bool) letName where
- showLetName :: letName -> String
- data SharingName = SharingName (StableName a)
- makeSharingName :: a -> SharingName
- newtype ObserveSharing letName repr a = ObserveSharing {
- unObserveSharing :: ReaderT (HashSet SharingName) (State (ObserveSharingState letName)) (CleanDefs letName repr a)
- observeSharing :: Eq letName => Hashable letName => ObserveSharing letName repr a -> repr a
- data ObserveSharingState letName = ObserveSharingState {
- oss_refs :: HashMap SharingName (letName, Int)
- oss_recs :: HashSet SharingName
- observeSharingNode :: Eq letName => Hashable letName => Letable letName repr => MakeLetName letName => ObserveSharing letName repr a -> ObserveSharing letName repr a
- newtype CleanDefs letName repr a = CleanDefs {
- unCleanDefs :: HashSet letName -> repr a
Class Letable
class Letable letName repr where Source #
This class is not for end-users like usual symantic operators,
here def
and ref
are introduced by observeSharing
.
Nothing
def :: letName -> repr a -> repr a Source #
(
let-binds def
letName x)(letName)
to be equal to (x)
.
ref :: Bool -> letName -> repr a Source #
(
is a reference to ref
isRec letName)(letName)
.
(isRec)
is True
iif. this ref
erence is recursive,
ie. is reachable within its def
inition.
def :: Liftable1 repr => Letable letName (Output repr) => letName -> repr a -> repr a Source #
(
let-binds def
letName x)(letName)
to be equal to (x)
.
ref :: Liftable repr => Letable letName (Output repr) => Bool -> letName -> repr a Source #
Instances
ShowLetName sN letName => Letable letName (WriteGrammar sN) Source # | |
Defined in Symantic.Parser.Grammar.Write def :: letName -> WriteGrammar sN a -> WriteGrammar sN a Source # ref :: Bool -> letName -> WriteGrammar sN a Source # | |
ShowLetName sN letName => Letable letName (ViewGrammar sN) Source # | |
Defined in Symantic.Parser.Grammar.View def :: letName -> ViewGrammar sN a -> ViewGrammar sN a Source # ref :: Bool -> letName -> ViewGrammar sN a Source # | |
(Letable letName repr, Typeable letName) => Letable letName (SomeComb repr) Source # | |
Routinable repr => Letable Name (Program repr inp) Source # | |
(Letable letName repr, Eq letName, Hashable letName) => Letable letName (CleanDefs letName repr) Source # | |
(Letable letName repr, MakeLetName letName, Eq letName, Hashable letName) => Letable letName (ObserveSharing letName repr) Source # | |
Defined in Symantic.Univariant.Letable def :: letName -> ObserveSharing letName repr a -> ObserveSharing letName repr a Source # ref :: Bool -> letName -> ObserveSharing letName repr a Source # | |
Letable letName repr => Trans (Comb (Letable letName) repr) repr Source # | |
data Comb (Letable letName) repr Source # | |
Class MakeLetName
class MakeLetName letName where Source #
makeLetName :: SharingName -> IO letName Source #
Instances
MakeLetName Name Source # | |
Defined in Symantic.Parser.Grammar.Optimize makeLetName :: SharingName -> IO Name Source # |
Type ShowLetName
class ShowLetName (showName :: Bool) letName where Source #
Useful on golden unit tests because StableName
change often when changing unrelated source code
or even changing basic GHC or executable flags.
showLetName :: letName -> String Source #
Instances
ShowLetName 'False letName Source # | Always return |
Defined in Symantic.Univariant.Letable showLetName :: letName -> String Source # | |
Show letName => ShowLetName 'True letName Source # | Like |
Defined in Symantic.Univariant.Letable showLetName :: letName -> String Source # |
Type SharingName
data SharingName Source #
Note that the observable sharing enabled by StableName
is not perfect as it will not observe all the sharing explicitely done.
Note also that the observed sharing could be different between ghc and ghci.
Instances
Eq SharingName Source # | |
Defined in Symantic.Univariant.Letable (==) :: SharingName -> SharingName -> Bool # (/=) :: SharingName -> SharingName -> Bool # | |
Hashable SharingName Source # | |
Defined in Symantic.Univariant.Letable hashWithSalt :: Int -> SharingName -> Int # hash :: SharingName -> Int # |
makeSharingName :: a -> SharingName Source #
(
is like makeSharingName
x)(
but it also forces
evaluation of makeStableName
x)(x)
to ensure that the StableName
is correct first time,
which avoids to produce a tree bigger than needed.
Note that this function uses unsafePerformIO
instead of returning in IO
,
this is apparently required to avoid infinite loops due to unstable StableName
in compiled code, and sometimes also in ghci.
Note that maybe pseq should be used here.
Type ObserveSharing
newtype ObserveSharing letName repr a Source #
Interpreter detecting some (Haskell embedded) let
definitions used at
least once and/or recursively, in order to replace them
with the def
and ref
combinators.
See Type-safe observable sharing in Haskell
ObserveSharing | |
|
Instances
(Letable letName repr, MakeLetName letName, Eq letName, Hashable letName) => Letable letName (ObserveSharing letName repr) Source # | |
Defined in Symantic.Univariant.Letable def :: letName -> ObserveSharing letName repr a -> ObserveSharing letName repr a Source # ref :: Bool -> letName -> ObserveSharing letName repr a Source # | |
(Letable letName repr, MakeLetName letName, Eq letName, Hashable letName, Satisfiable tok repr) => Satisfiable tok (ObserveSharing letName repr) Source # | |
Defined in Symantic.Parser.Grammar.ObserveSharing satisfy :: [ErrorItem tok] -> TermGrammar (tok -> Bool) -> ObserveSharing letName repr tok Source # item :: ObserveSharing letName repr tok Source # | |
(Letable letName repr, MakeLetName letName, Eq letName, Hashable letName, Lookable repr) => Lookable (ObserveSharing letName repr) Source # | |
Defined in Symantic.Parser.Grammar.ObserveSharing look :: ObserveSharing letName repr a -> ObserveSharing letName repr a Source # negLook :: ObserveSharing letName repr a -> ObserveSharing letName repr () Source # eof :: ObserveSharing letName repr () Source # | |
(Letable letName repr, MakeLetName letName, Eq letName, Hashable letName, Foldable repr, Applicable repr, Alternable repr) => Foldable (ObserveSharing letName repr) Source # | |
Defined in Symantic.Parser.Grammar.ObserveSharing chainPre :: ObserveSharing letName repr (a -> a) -> ObserveSharing letName repr a -> ObserveSharing letName repr a Source # chainPost :: ObserveSharing letName repr a -> ObserveSharing letName repr (a -> a) -> ObserveSharing letName repr a Source # | |
(Letable letName repr, MakeLetName letName, Eq letName, Hashable letName, Matchable repr) => Matchable (ObserveSharing letName repr) Source # | |
Defined in Symantic.Parser.Grammar.ObserveSharing conditional :: Eq a => ObserveSharing letName repr a -> [TermGrammar (a -> Bool)] -> [ObserveSharing letName repr b] -> ObserveSharing letName repr b -> ObserveSharing letName repr b Source # match :: Eq a => ObserveSharing letName repr a -> [TermGrammar a] -> (TermGrammar a -> ObserveSharing letName repr b) -> ObserveSharing letName repr b -> ObserveSharing letName repr b Source # | |
(Letable letName repr, MakeLetName letName, Eq letName, Hashable letName, Selectable repr) => Selectable (ObserveSharing letName repr) Source # | |
Defined in Symantic.Parser.Grammar.ObserveSharing branch :: ObserveSharing letName repr (Either a b) -> ObserveSharing letName repr (a -> c) -> ObserveSharing letName repr (b -> c) -> ObserveSharing letName repr c Source # | |
(Letable letName repr, MakeLetName letName, Eq letName, Hashable letName, Alternable repr) => Alternable (ObserveSharing letName repr) Source # | |
Defined in Symantic.Parser.Grammar.ObserveSharing (<|>) :: ObserveSharing letName repr a -> ObserveSharing letName repr a -> ObserveSharing letName repr a Source # empty :: ObserveSharing letName repr a Source # try :: ObserveSharing letName repr a -> ObserveSharing letName repr a Source # (<+>) :: (Applicable (ObserveSharing letName repr), Alternable (ObserveSharing letName repr)) => ObserveSharing letName repr a -> ObserveSharing letName repr b -> ObserveSharing letName repr (Either a b) Source # | |
(Letable letName repr, MakeLetName letName, Eq letName, Hashable letName, Applicable repr) => Applicable (ObserveSharing letName repr) Source # | |
Defined in Symantic.Parser.Grammar.ObserveSharing (<$>) :: TermGrammar (a -> b) -> ObserveSharing letName repr a -> ObserveSharing letName repr b Source # (<&>) :: ObserveSharing letName repr a -> TermGrammar (a -> b) -> ObserveSharing letName repr b Source # (<$) :: TermGrammar a -> ObserveSharing letName repr b -> ObserveSharing letName repr a Source # ($>) :: ObserveSharing letName repr a -> TermGrammar b -> ObserveSharing letName repr b Source # pure :: TermGrammar a -> ObserveSharing letName repr a Source # (<*>) :: ObserveSharing letName repr (a -> b) -> ObserveSharing letName repr a -> ObserveSharing letName repr b Source # liftA2 :: TermGrammar (a -> b -> c) -> ObserveSharing letName repr a -> ObserveSharing letName repr b -> ObserveSharing letName repr c Source # (<*) :: ObserveSharing letName repr a -> ObserveSharing letName repr b -> ObserveSharing letName repr a Source # (*>) :: ObserveSharing letName repr a -> ObserveSharing letName repr b -> ObserveSharing letName repr b Source # (<**>) :: ObserveSharing letName repr a -> ObserveSharing letName repr (a -> b) -> ObserveSharing letName repr b Source # | |
(Letable letName repr, MakeLetName letName, Eq letName, Hashable letName) => Trans3 (CleanDefs letName repr) (ObserveSharing letName repr) Source # | |
Defined in Symantic.Univariant.Letable trans3 :: (CleanDefs letName repr a -> CleanDefs letName repr b -> CleanDefs letName repr c -> CleanDefs letName repr d) -> ObserveSharing letName repr a -> ObserveSharing letName repr b -> ObserveSharing letName repr c -> ObserveSharing letName repr d Source # | |
(Letable letName repr, MakeLetName letName, Eq letName, Hashable letName) => Trans2 (CleanDefs letName repr) (ObserveSharing letName repr) Source # | |
Defined in Symantic.Univariant.Letable trans2 :: (CleanDefs letName repr a -> CleanDefs letName repr b -> CleanDefs letName repr c) -> ObserveSharing letName repr a -> ObserveSharing letName repr b -> ObserveSharing letName repr c Source # | |
(Letable letName repr, MakeLetName letName, Eq letName, Hashable letName) => Trans1 (CleanDefs letName repr) (ObserveSharing letName repr) Source # | |
Defined in Symantic.Univariant.Letable trans1 :: (CleanDefs letName repr a -> CleanDefs letName repr b) -> ObserveSharing letName repr a -> ObserveSharing letName repr b Source # | |
(Letable letName repr, MakeLetName letName, Eq letName, Hashable letName) => Trans (CleanDefs letName repr) (ObserveSharing letName repr) Source # | |
Defined in Symantic.Univariant.Letable trans :: CleanDefs letName repr a -> ObserveSharing letName repr a Source # | |
type Output (ObserveSharing letName repr) Source # | |
Defined in Symantic.Univariant.Letable |
observeSharing :: Eq letName => Hashable letName => ObserveSharing letName repr a -> repr a Source #
Type ObserveSharingState
data ObserveSharingState letName Source #
ObserveSharingState | |
|
observeSharingNode :: Eq letName => Hashable letName => Letable letName repr => MakeLetName letName => ObserveSharing letName repr a -> ObserveSharing letName repr a Source #
Type CleanDefs
newtype CleanDefs letName repr a Source #
Remove def
when non-recursive or unused.
CleanDefs | |
|
Instances
Trans3 repr (CleanDefs letName repr) Source # | |
Trans2 repr (CleanDefs letName repr) Source # | |
Trans1 repr (CleanDefs letName repr) Source # | |
Trans repr (CleanDefs letName repr) Source # | |
Defined in Symantic.Univariant.Letable | |
(Letable letName repr, Eq letName, Hashable letName) => Letable letName (CleanDefs letName repr) Source # | |
Satisfiable tok repr => Satisfiable tok (CleanDefs letName repr) Source # | |
Lookable repr => Lookable (CleanDefs letName repr) Source # | |
Foldable repr => Foldable (CleanDefs letName repr) Source # | |
Matchable repr => Matchable (CleanDefs letName repr) Source # | |
Defined in Symantic.Parser.Grammar.ObserveSharing conditional :: Eq a => CleanDefs letName repr a -> [TermGrammar (a -> Bool)] -> [CleanDefs letName repr b] -> CleanDefs letName repr b -> CleanDefs letName repr b Source # match :: Eq a => CleanDefs letName repr a -> [TermGrammar a] -> (TermGrammar a -> CleanDefs letName repr b) -> CleanDefs letName repr b -> CleanDefs letName repr b Source # | |
Selectable repr => Selectable (CleanDefs letName repr) Source # | |
Alternable repr => Alternable (CleanDefs letName repr) Source # | |
Defined in Symantic.Parser.Grammar.ObserveSharing (<|>) :: CleanDefs letName repr a -> CleanDefs letName repr a -> CleanDefs letName repr a Source # empty :: CleanDefs letName repr a Source # try :: CleanDefs letName repr a -> CleanDefs letName repr a Source # (<+>) :: (Applicable (CleanDefs letName repr), Alternable (CleanDefs letName repr)) => CleanDefs letName repr a -> CleanDefs letName repr b -> CleanDefs letName repr (Either a b) Source # | |
Applicable repr => Applicable (CleanDefs letName repr) Source # | |
Defined in Symantic.Parser.Grammar.ObserveSharing (<$>) :: TermGrammar (a -> b) -> CleanDefs letName repr a -> CleanDefs letName repr b Source # (<&>) :: CleanDefs letName repr a -> TermGrammar (a -> b) -> CleanDefs letName repr b Source # (<$) :: TermGrammar a -> CleanDefs letName repr b -> CleanDefs letName repr a Source # ($>) :: CleanDefs letName repr a -> TermGrammar b -> CleanDefs letName repr b Source # pure :: TermGrammar a -> CleanDefs letName repr a Source # (<*>) :: CleanDefs letName repr (a -> b) -> CleanDefs letName repr a -> CleanDefs letName repr b Source # liftA2 :: TermGrammar (a -> b -> c) -> CleanDefs letName repr a -> CleanDefs letName repr b -> CleanDefs letName repr c Source # (<*) :: CleanDefs letName repr a -> CleanDefs letName repr b -> CleanDefs letName repr a Source # (*>) :: CleanDefs letName repr a -> CleanDefs letName repr b -> CleanDefs letName repr b Source # (<**>) :: CleanDefs letName repr a -> CleanDefs letName repr (a -> b) -> CleanDefs letName repr b Source # | |
(Letable letName repr, MakeLetName letName, Eq letName, Hashable letName) => Trans3 (CleanDefs letName repr) (ObserveSharing letName repr) Source # | |
Defined in Symantic.Univariant.Letable trans3 :: (CleanDefs letName repr a -> CleanDefs letName repr b -> CleanDefs letName repr c -> CleanDefs letName repr d) -> ObserveSharing letName repr a -> ObserveSharing letName repr b -> ObserveSharing letName repr c -> ObserveSharing letName repr d Source # | |
(Letable letName repr, MakeLetName letName, Eq letName, Hashable letName) => Trans2 (CleanDefs letName repr) (ObserveSharing letName repr) Source # | |
Defined in Symantic.Univariant.Letable trans2 :: (CleanDefs letName repr a -> CleanDefs letName repr b -> CleanDefs letName repr c) -> ObserveSharing letName repr a -> ObserveSharing letName repr b -> ObserveSharing letName repr c Source # | |
(Letable letName repr, MakeLetName letName, Eq letName, Hashable letName) => Trans1 (CleanDefs letName repr) (ObserveSharing letName repr) Source # | |
Defined in Symantic.Univariant.Letable trans1 :: (CleanDefs letName repr a -> CleanDefs letName repr b) -> ObserveSharing letName repr a -> ObserveSharing letName repr b Source # | |
(Letable letName repr, MakeLetName letName, Eq letName, Hashable letName) => Trans (CleanDefs letName repr) (ObserveSharing letName repr) Source # | |
Defined in Symantic.Univariant.Letable trans :: CleanDefs letName repr a -> ObserveSharing letName repr a Source # | |
type Output (CleanDefs _letName repr) Source # | |
Defined in Symantic.Univariant.Letable |