hpastetwo
recent
new
New Revision
Lightweight pure functional monad-free type-safe coroutines. > import Prelude hiding (read, return) > read cont (i, is) = cont i is > write o cont is = (x, (o, os)) where (x, os) = cont is > return x is = (x, ()) Unlikely as it sounds, that code was motivated by http://www.dpmms.cam.ac.uk/~martin/Research/Publications/2007/hp07.pdf > chat alice bob = (alice_value, bob_value) where > (alice_value, alice_output) = alice bob_output > (bob_value, bob_output ) = bob alice_output Example: Diffie-Hellman key exchange. See http://en.wikipedia.org/wiki/Diffie–Hellman_key_exchange > p = 23 > g = 5 > alice a = > write "Hello" $ > write (g^a `mod` p) $ > read $ \b -> > let s = b^a `mod` p in > write "Goodbye" $ > return s > bob b = > read $ \message1 -> > write (g^b `mod` p) $ > read $ \a -> > let s = a^b `mod` p in > read $ \message2 -> > return s > main = print $ chat (alice 6) (bob 15)
author
title
language
ActionScript
ActionScript 3
ApacheConf
AppleScript
BBCode
Bash
Batchfile
Befunge
Boo
Brainfuck
C
C#
C++
CSS
CSS+Django/Jinja
CSS+Genshi Text
CSS+Mako
CSS+Myghty
CSS+PHP
CSS+Ruby
CSS+Smarty
Cheetah
Clojure
Common Lisp
D
Darcs Patch
Debian Control file
Debian Sourcelist
Delphi
Diff
Django/Jinja
Dylan
ERB
Erlang
Fortran
GAS
Genshi
Genshi Text
Gettext Catalog
Gnuplot
Groff
HTML
HTML+Cheetah
HTML+Django/Jinja
HTML+Genshi
HTML+Mako
HTML+Myghty
HTML+PHP
HTML+Smarty
Haskell
INI
IRC logs
Io
Java
Java Server Page
JavaScript
JavaScript+Cheetah
JavaScript+Django/Jinja
JavaScript+Genshi Text
JavaScript+Mako
JavaScript+Myghty
JavaScript+PHP
JavaScript+Ruby
JavaScript+Smarty
LLVM
Lighttpd configuration file
Literate Haskell
Logtalk
Lua
MOOCode
Makefile
Makefile
Mako
Matlab
Matlab session
MiniD
MoinMoin/Trac Wiki markup
MuPAD
MySQL
Myghty
NASM
Nginx configuration file
NumPy
OCaml
Objective-C
PHP
POVRay
Perl
Python
Python 3
Python 3.0 Traceback
Python Traceback
Python console session
RHTML
Raw token data
Redcode
Ruby
Ruby irb session
S
SQL
Scala
Scheme
Smalltalk
Smarty
SquidConf
Tcl
Tcsh
TeX
Text only
VB.net
VimL
XML
XML+Cheetah
XML+Django/Jinja
XML+Mako
XML+Myghty
XML+PHP
XML+Ruby
XML+Smarty
XSLT
YAML
c-objdump
cpp-objdump
d-objdump
objdump
reStructuredText
sqlite3con
channel
none