@@ -10,11 +10,12 @@ License : MIT
10Maintainer : Paweł Nowak <pawel834@gmail.com>
10Maintainer : Paweł Nowak <pawel834@gmail.com>
11Stability : experimental
11Stability : experimental
13−Abstract syntax descriptions based on semi-isomorphisms.
13+Reversible parsing and pretty-printing.
15module Data.Syntax (
15module Data.Syntax (
16 -- * Syntax.
16 -- * Syntax.
17 Syntax(..),
17 Syntax(..),
18 -- * Common isomorphisms.
19 -- * Common isomorphisms.
@@ -110,3 +111,19 @@ instance Syntax syn => Syntax (ReaderCT env syn) where
110 takeWhile1 = clift . takeWhile1
111 takeWhile1 = clift . takeWhile1
111 takeTill = clift . takeTill
112 takeTill = clift . takeTill
112 takeTill1 = clift . takeTill1
113 takeTill1 = clift . takeTill1
115+-- | Execute a computation in an isolated context.
117+-- The motivating example: you want to write a function
119+-- > serializeList :: Syntax syn => syn () a -> syn () [a]
121+-- Notice that we cannot just use simany, because the first @syn () a@
122+-- could eat the entire sequence (even though we printed more than 1 value!), so
123+-- we have to insert some kind of separators between the element. But how can we
124+-- be sure that @syn () a@ will not eat our separators? We can't! Thats why we
125+-- have to do the parsing in two stages: first extract the sequence between separators,
126+-- then run the @syn () a@ on this sequence.
127+class Syntax syn => Isolable syn where
128+ -- | Turns a computation into one executed in an isolated context.
129+ isolate :: syn () b -> syn (Seq syn) b