[cap-talk] Abstractions that subsume capabilities
Richard Uhtenwoldt
notprivate2 at gmail.com
Sat Mar 15 01:00:33 EDT 2008
Here is Pierre's code translated into Haskell. I changed the
name "file" to "handle" to conform to Haskell naming conventions.
--8<---- MakeFilePrinter.hs ---------------------------------------------
module MakeFilePrinter where
import IO
makeFilePrinter handle output_function = let
printer = do
contents <- hGetContents handle
mapM_ output_function (lines contents)
in
return printer
--8<---------------------------------------------------------------------
import MakeFilePrinter
import IO
main = do
handle <- openFile "foo.txt" ReadMode
filePrinter <- makeFilePrinter handle putStrLn
filePrinter
The above code mirrors the structure of the E code as closely as
possible at the cost of being atypical Haskell in at least one
way: it would be atypical for a Haskell programmer to introduce
the variable printer. Instead he would tend to write,
makeFilePrinter handle output_function = return $ do
contents <- hGetContents handle
mapM_ output_function (lines contents)
This is a second illustration of the point that a large fraction
of E code can be translated into Haskell code in a routine or
mechanical fashion, which is unsurprising since both languages
use the lambda calculus as an organizing idea.
--
Text by me above is hereby placed in the public domain.
More information about the cap-talk
mailing list