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 = forall a. SharingName (StableName a)
- makeSharingName :: a -> SharingName
- newtype ObserveSharing letName repr a = ObserveSharing {
- unObserveSharing :: ReaderT (HashSet SharingName) (State (ObserveSharingState letName)) (FinalizeSharing letName repr a)
- observeSharing :: Eq letName => Hashable letName => Show letName => ObserveSharing letName repr a -> WithSharing letName repr a
- data SomeLet repr = forall a. SomeLet (repr a)
- type WithSharing letName repr a = (repr a, HashMap letName (SomeLet repr))
- data ObserveSharingState letName = ObserveSharingState {
- oss_refs :: HashMap SharingName (letName, Int)
- oss_recs :: HashSet SharingName
- observeSharingNode :: Eq letName => Hashable letName => Show letName => Letable letName repr => MakeLetName letName => ObserveSharing letName repr a -> ObserveSharing letName repr a
- newtype FinalizeSharing letName repr a = FinalizeSharing {
- unFinalizeSharing :: ReaderT (HashSet letName) (Writer (LetBindings letName repr)) (repr a)
- type LetBindings letName repr = HashMap letName (SomeLet repr)
- class Letsable letName repr where
- lets :: LetBindings letName repr -> repr a -> repr a
Class Letable
class Letable letName repr where Source #
This class is not for end-users like usual symantic operators,
here shareable
and ref
are introduced by observeSharing
.
Nothing
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 shareable
definition.
shareable :: letName -> repr a -> repr a Source #
(
let-binds shareable
letName x)(letName)
to be equal to (x)
.
default shareable :: FromDerived1 (Letable letName) repr => letName -> repr a -> repr a Source #
Instances
(Letable letName repr, Eq letName, Hashable letName, Show letName) => Letable letName (FinalizeSharing letName repr) Source # | |
Defined in Symantic.Typed.ObserveSharing ref :: Bool -> letName -> FinalizeSharing letName repr a Source # shareable :: letName -> FinalizeSharing letName repr a -> FinalizeSharing letName repr a Source # | |
Letable letName (ObserveSharing letName repr) Source # | |
Defined in Symantic.Typed.ObserveSharing ref :: Bool -> letName -> ObserveSharing letName repr a Source # shareable :: letName -> ObserveSharing letName repr a -> ObserveSharing letName repr a Source # |
Class MakeLetName
class MakeLetName letName where Source #
makeLetName :: SharingName -> IO letName 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.Typed.ObserveSharing showLetName :: letName -> String Source # | |
Show letName => ShowLetName 'True letName Source # | Like |
Defined in Symantic.Typed.ObserveSharing 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.
forall a. SharingName (StableName a) |
Instances
Eq SharingName Source # | |
Defined in Symantic.Typed.ObserveSharing (==) :: SharingName -> SharingName -> Bool # (/=) :: SharingName -> SharingName -> Bool # | |
Hashable SharingName Source # | |
Defined in Symantic.Typed.ObserveSharing 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 #
ObserveSharing | |
|
Instances
observeSharing :: Eq letName => Hashable letName => Show letName => ObserveSharing letName repr a -> WithSharing 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 shareable
and ref
combinators.
See Type-safe observable sharing in Haskell
Beware not to apply observeSharing
more than once on the same term
otherwise some shareable
introduced by the first call
would be removed by the second call.
Type SomeLet
Type WithSharing
type WithSharing letName repr a = (repr a, HashMap letName (SomeLet repr)) Source #
Type ObserveSharingState
data ObserveSharingState letName Source #
ObserveSharingState | |
|
observeSharingNode :: Eq letName => Hashable letName => Show letName => Letable letName repr => MakeLetName letName => ObserveSharing letName repr a -> ObserveSharing letName repr a Source #
Type FinalizeSharing
newtype FinalizeSharing letName repr a Source #
FinalizeSharing | |
|
Instances
Type LetBindings
type LetBindings letName repr = HashMap letName (SomeLet repr) Source #
Class Letsable
class Letsable letName repr where Source #
Nothing
lets :: LetBindings letName repr -> repr a -> repr a Source #
(
let-binds lets
defs x)(defs)
in (x)
.
default lets :: Derivable repr => FromDerived1 (Letsable letName) repr => LetBindings letName repr -> repr a -> repr a Source #
Instances
Letsable letName (ObserveSharing letName repr) Source # | |
Defined in Symantic.Typed.ObserveSharing lets :: LetBindings letName (ObserveSharing letName repr) -> ObserveSharing letName repr a -> ObserveSharing letName repr a Source # |