on master help sign in
Added Isolated.
commit1593877da828417b34acfe5bf7c291fb570aaa03 authorPaweł Nowak <pawel834@gmail.com> dateThu 11 Dec 2014, 22:35 (12 years ago) parent37b9748
1 file changed+18−1
Data/Syntax.hs+18−1
Data/Syntax.hs+18−1
@@ -10,11 +10,12 @@ License : MIT
1010Maintainer : Paweł Nowak <pawel834@gmail.com>
1111Stability : experimental
1212
13−Abstract syntax descriptions based on semi-isomorphisms.
13+Reversible parsing and pretty-printing.
1414-}
1515module Data.Syntax (
1616 -- * Syntax.
1717 Syntax(..),
18+ Isolable(..),
1819 -- * Common isomorphisms.
1920 packed
2021 ) where
@@ -110,3 +111,19 @@ instance Syntax syn => Syntax (ReaderCT env syn) where
110111 takeWhile1 = clift . takeWhile1
111112 takeTill = clift . takeTill
112113 takeTill1 = clift . takeTill1
114+
115+-- | Execute a computation in an isolated context.
116+--
117+-- The motivating example: you want to write a function
118+--
119+-- > serializeList :: Syntax syn => syn () a -> syn () [a]
120+--
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