equal
deleted
inserted
replaced
167 fun tr' (f::ts) = |
167 fun tr' (f::ts) = |
168 list_comb (Const ("_do", dummyT) $ unfold_monad f, ts) |
168 list_comb (Const ("_do", dummyT) $ unfold_monad f, ts) |
169 in [(@{const_syntax "run"}, tr')] end; |
169 in [(@{const_syntax "run"}, tr')] end; |
170 *} |
170 *} |
171 |
171 |
172 subsubsection {* Plain evaluation *} |
|
173 |
|
174 definition |
|
175 evaluate :: "'a Heap \<Rightarrow> 'a" |
|
176 where |
|
177 [code del]: "evaluate f = (case execute f Heap.empty |
|
178 of (Inl x, _) \<Rightarrow> x)" |
|
179 |
|
180 |
172 |
181 subsection {* Monad properties *} |
173 subsection {* Monad properties *} |
182 |
174 |
183 subsubsection {* Superfluous runs *} |
175 subsubsection {* Superfluous runs *} |
184 |
176 |
328 {*import qualified Control.Monad; |
320 {*import qualified Control.Monad; |
329 import qualified Control.Monad.ST; |
321 import qualified Control.Monad.ST; |
330 import qualified Data.STRef; |
322 import qualified Data.STRef; |
331 import qualified Data.Array.ST; |
323 import qualified Data.Array.ST; |
332 |
324 |
|
325 type RealWorld = Control.Monad.ST.RealWorld; |
333 type ST s a = Control.Monad.ST.ST s a; |
326 type ST s a = Control.Monad.ST.ST s a; |
334 type STRef s a = Data.STRef.STRef s a; |
327 type STRef s a = Data.STRef.STRef s a; |
335 type STArray s a = Data.Array.ST.STArray s Int a; |
328 type STArray s a = Data.Array.ST.STArray s Int a; |
336 |
329 |
337 runST :: (forall s. ST s a) -> a; |
330 runST :: (forall s. ST s a) -> a; |
354 readArray = Data.Array.ST.readArray; |
347 readArray = Data.Array.ST.readArray; |
355 |
348 |
356 writeArray :: STArray s a -> Int -> a -> ST s (); |
349 writeArray :: STArray s a -> Int -> a -> ST s (); |
357 writeArray = Data.Array.ST.writeArray;*} |
350 writeArray = Data.Array.ST.writeArray;*} |
358 |
351 |
359 code_reserved Haskell ST STRef Array |
352 code_reserved Haskell RealWorld ST STRef Array |
360 runST |
353 runST |
361 newSTRef reasSTRef writeSTRef |
354 newSTRef reasSTRef writeSTRef |
362 newArray newListArray lengthArray readArray writeArray |
355 newArray newListArray lengthArray readArray writeArray |
363 |
356 |
364 text {* Monad *} |
357 text {* Monad *} |
365 |
358 |
366 code_type Heap (Haskell "ST '_s _") |
359 code_type Heap (Haskell "ST/ RealWorld/ _") |
367 code_const Heap (Haskell "error \"bare Heap\")") |
360 code_const Heap (Haskell "error/ \"bare Heap\"") |
368 code_const evaluate (Haskell "runST") |
|
369 code_monad run "op \<guillemotright>=" Haskell |
361 code_monad run "op \<guillemotright>=" Haskell |
370 code_const return (Haskell "return") |
362 code_const return (Haskell "return") |
371 code_const "Heap_Monad.Fail" (Haskell "_") |
363 code_const "Heap_Monad.Fail" (Haskell "_") |
372 code_const "Heap_Monad.raise_exc" (Haskell "error") |
364 code_const "Heap_Monad.raise_exc" (Haskell "error") |
373 |
365 |