symantic-parser-0.1.0.20210201: Parser combinators statically optimized and staged via typed meta-programming
Safe HaskellNone
LanguageHaskell2010

Symantic.Univariant.Letable

Synopsis

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.

Minimal complete definition

Nothing

Methods

def :: letName -> repr a -> repr a Source #

(def letName x) let-binds (letName) to be equal to (x).

ref :: Bool -> letName -> repr a Source #

(ref isRec letName) is a reference to (letName). (isRec) is True iif. this reference is recursive, ie. is reachable within its definition.

def :: Liftable1 repr => Letable letName (Output repr) => letName -> repr a -> repr a Source #

(def letName x) let-binds (letName) to be equal to (x).

ref :: Liftable repr => Letable letName (Output repr) => Bool -> letName -> repr a Source #

(ref isRec letName) is a reference to (letName). (isRec) is True iif. this reference is recursive, ie. is reachable within its definition.

Instances

Instances details
ShowLetName sN letName => Letable letName (WriteGrammar sN) Source # 
Instance details

Defined in Symantic.Parser.Grammar.Write

Methods

def :: letName -> WriteGrammar sN a -> WriteGrammar sN a Source #

ref :: Bool -> letName -> WriteGrammar sN a Source #

ShowLetName sN letName => Letable letName (ViewGrammar sN) Source # 
Instance details

Defined in Symantic.Parser.Grammar.View

Methods

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 # 
Instance details

Defined in Symantic.Parser.Grammar.Optimize

Methods

def :: letName -> SomeComb repr a -> SomeComb repr a Source #

ref :: Bool -> letName -> SomeComb repr a Source #

Routinable repr => Letable Name (Program repr inp) Source # 
Instance details

Defined in Symantic.Parser.Machine.Program

Methods

def :: Name -> Program repr inp a -> Program repr inp a Source #

ref :: Bool -> Name -> Program repr inp a Source #

(Letable letName repr, Eq letName, Hashable letName) => Letable letName (CleanDefs letName repr) Source # 
Instance details

Defined in Symantic.Univariant.Letable

Methods

def :: letName -> CleanDefs letName repr a -> CleanDefs letName repr a Source #

ref :: Bool -> letName -> CleanDefs letName repr a Source #

(Letable letName repr, MakeLetName letName, Eq letName, Hashable letName) => Letable letName (ObserveSharing letName repr) Source # 
Instance details

Defined in Symantic.Univariant.Letable

Methods

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 # 
Instance details

Defined in Symantic.Parser.Grammar.Optimize

Methods

trans :: Comb (Letable letName) repr a -> repr a Source #

data Comb (Letable letName) repr Source # 
Instance details

Defined in Symantic.Parser.Grammar.Optimize

data Comb (Letable letName) repr where

Class MakeLetName

class MakeLetName letName where Source #

Methods

makeLetName :: SharingName -> IO letName Source #

Instances

Instances details
MakeLetName Name Source # 
Instance details

Defined in Symantic.Parser.Grammar.Optimize

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.

Methods

showLetName :: letName -> String Source #

Instances

Instances details
ShowLetName 'False letName Source #

Always return "hidden",

Instance details

Defined in Symantic.Univariant.Letable

Methods

showLetName :: letName -> String Source #

Show letName => ShowLetName 'True letName Source #

Like Show.

Instance details

Defined in Symantic.Univariant.Letable

Methods

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.

Constructors

SharingName (StableName a) 

Instances

Instances details
Eq SharingName Source # 
Instance details

Defined in Symantic.Univariant.Letable

Hashable SharingName Source # 
Instance details

Defined in Symantic.Univariant.Letable

makeSharingName :: a -> SharingName Source #

(makeSharingName x) is like (makeStableName x) but it also forces evaluation of (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

Constructors

ObserveSharing 

Instances

Instances details
(Letable letName repr, MakeLetName letName, Eq letName, Hashable letName) => Letable letName (ObserveSharing letName repr) Source # 
Instance details

Defined in Symantic.Univariant.Letable

Methods

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 # 
Instance details

Defined in Symantic.Parser.Grammar.ObserveSharing

Methods

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 # 
Instance details

Defined in Symantic.Parser.Grammar.ObserveSharing

Methods

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 # 
Instance details

Defined in Symantic.Parser.Grammar.ObserveSharing

Methods

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 # 
Instance details

Defined in Symantic.Parser.Grammar.ObserveSharing

Methods

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 # 
Instance details

Defined in Symantic.Parser.Grammar.ObserveSharing

Methods

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 # 
Instance details

Defined in Symantic.Parser.Grammar.ObserveSharing

Methods

(<|>) :: 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 # 
Instance details

Defined in Symantic.Parser.Grammar.ObserveSharing

Methods

(<$>) :: 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 # 
Instance details

Defined in Symantic.Univariant.Letable

Methods

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 # 
Instance details

Defined in Symantic.Univariant.Letable

Methods

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 # 
Instance details

Defined in Symantic.Univariant.Letable

Methods

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 # 
Instance details

Defined in Symantic.Univariant.Letable

Methods

trans :: CleanDefs letName repr a -> ObserveSharing letName repr a Source #

type Output (ObserveSharing letName repr) Source # 
Instance details

Defined in Symantic.Univariant.Letable

type Output (ObserveSharing letName repr) = CleanDefs letName repr

observeSharing :: Eq letName => Hashable letName => ObserveSharing letName repr a -> repr a Source #

Type ObserveSharingState

data ObserveSharingState letName Source #

Constructors

ObserveSharingState 

Fields

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.

Constructors

CleanDefs 

Fields

Instances

Instances details
Trans3 repr (CleanDefs letName repr) Source # 
Instance details

Defined in Symantic.Univariant.Letable

Methods

trans3 :: (repr a -> repr b -> repr c -> repr d) -> CleanDefs letName repr a -> CleanDefs letName repr b -> CleanDefs letName repr c -> CleanDefs letName repr d Source #

Trans2 repr (CleanDefs letName repr) Source # 
Instance details

Defined in Symantic.Univariant.Letable

Methods

trans2 :: (repr a -> repr b -> repr c) -> CleanDefs letName repr a -> CleanDefs letName repr b -> CleanDefs letName repr c Source #

Trans1 repr (CleanDefs letName repr) Source # 
Instance details

Defined in Symantic.Univariant.Letable

Methods

trans1 :: (repr a -> repr b) -> CleanDefs letName repr a -> CleanDefs letName repr b Source #

Trans repr (CleanDefs letName repr) Source # 
Instance details

Defined in Symantic.Univariant.Letable

Methods

trans :: repr a -> CleanDefs letName repr a Source #

(Letable letName repr, Eq letName, Hashable letName) => Letable letName (CleanDefs letName repr) Source # 
Instance details

Defined in Symantic.Univariant.Letable

Methods

def :: letName -> CleanDefs letName repr a -> CleanDefs letName repr a Source #

ref :: Bool -> letName -> CleanDefs letName repr a Source #

Satisfiable tok repr => Satisfiable tok (CleanDefs letName repr) Source # 
Instance details

Defined in Symantic.Parser.Grammar.ObserveSharing

Methods

satisfy :: [ErrorItem tok] -> TermGrammar (tok -> Bool) -> CleanDefs letName repr tok Source #

item :: CleanDefs letName repr tok Source #

Lookable repr => Lookable (CleanDefs letName repr) Source # 
Instance details

Defined in Symantic.Parser.Grammar.ObserveSharing

Methods

look :: CleanDefs letName repr a -> CleanDefs letName repr a Source #

negLook :: CleanDefs letName repr a -> CleanDefs letName repr () Source #

eof :: CleanDefs letName repr () Source #

Foldable repr => Foldable (CleanDefs letName repr) Source # 
Instance details

Defined in Symantic.Parser.Grammar.ObserveSharing

Methods

chainPre :: CleanDefs letName repr (a -> a) -> CleanDefs letName repr a -> CleanDefs letName repr a Source #

chainPost :: CleanDefs letName repr a -> CleanDefs letName repr (a -> a) -> CleanDefs letName repr a Source #

Matchable repr => Matchable (CleanDefs letName repr) Source # 
Instance details

Defined in Symantic.Parser.Grammar.ObserveSharing

Methods

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 # 
Instance details

Defined in Symantic.Parser.Grammar.ObserveSharing

Methods

branch :: CleanDefs letName repr (Either a b) -> CleanDefs letName repr (a -> c) -> CleanDefs letName repr (b -> c) -> CleanDefs letName repr c Source #

Alternable repr => Alternable (CleanDefs letName repr) Source # 
Instance details

Defined in Symantic.Parser.Grammar.ObserveSharing

Methods

(<|>) :: 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 # 
Instance details

Defined in Symantic.Parser.Grammar.ObserveSharing

Methods

(<$>) :: 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 # 
Instance details

Defined in Symantic.Univariant.Letable

Methods

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 # 
Instance details

Defined in Symantic.Univariant.Letable

Methods

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 # 
Instance details

Defined in Symantic.Univariant.Letable

Methods

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 # 
Instance details

Defined in Symantic.Univariant.Letable

Methods

trans :: CleanDefs letName repr a -> ObserveSharing letName repr a Source #

type Output (CleanDefs _letName repr) Source # 
Instance details

Defined in Symantic.Univariant.Letable

type Output (CleanDefs _letName repr) = repr