ImperativeHaskell 0.1.0.1 → 0.2.0.0
raw patch · 177 files changed
+1954/−67 lines, 177 filesbinary-added
Files
- .git/COMMIT_EDITMSG +1/−0
- .git/HEAD +1/−0
- .git/config +12/−0
- .git/description +1/−0
- .git/hooks/applypatch-msg.sample +15/−0
- .git/hooks/commit-msg.sample +24/−0
- .git/hooks/post-commit.sample +8/−0
- .git/hooks/post-receive.sample +15/−0
- .git/hooks/post-update.sample +8/−0
- .git/hooks/pre-applypatch.sample +14/−0
- .git/hooks/pre-commit.sample +46/−0
- .git/hooks/pre-rebase.sample +169/−0
- .git/hooks/prepare-commit-msg.sample +36/−0
- .git/hooks/update.sample +128/−0
- .git/index binary
- .git/info/exclude +6/−0
- .git/logs/HEAD +10/−0
- .git/logs/refs/heads/master +10/−0
- .git/logs/refs/remotes/origin/master +3/−0
- .git/objects/01/6acde47628279b666290c9dc9191adb7dc653a binary
- .git/objects/0a/1abd5de3cf5822c055651be49c0740da2dbb10 binary
- .git/objects/0b/7d578c0025e285b92f790f55ca47ffae3a5fe7 binary
- .git/objects/11/a89507307aeab1a1284fedbce84afc91a0c992 binary
- .git/objects/13/ea5de1f48b6023a4416b1d1fa8f93b0dfcad6d +2/−0
- .git/objects/16/fe73c8a57c56fa51da5ed4d259614270f45c44 binary
- .git/objects/1b/7ae0fd289a218bb3c18711bbb72e0d2f6ff52d binary
- .git/objects/22/c324eaf52c21034500ee0054f5d7057ed9cb95 +1/−0
- .git/objects/32/20183a054c44174eca29bd7e4f74253fa98d1b binary
- .git/objects/3c/71805404049f0d64221313415cca97d5bfa15f binary
- .git/objects/3d/f66baae2b65e3cc058cd4b96c923395231ec0d binary
- .git/objects/3f/f4f6afff27246be0b826adf182e09134a9f0d4 binary
- .git/objects/4c/ee439117e43cf393fde2d5400edfbd98a2c026 +2/−0
- .git/objects/52/f49ecd1fcef550c86e7af737810a84c463a5fb binary
- .git/objects/53/c4b3fec17c1360de0070e11e57d94dfd55ec37 binary
- .git/objects/56/6b9fea2f24763dd382cdaafb4996b3a6b6dea6 +1/−0
- .git/objects/5b/d6e430e9a65225607dd76ca7384e8d15890a03 +3/−0
- .git/objects/61/553f3af4ea8927fa6e83e4bde2eb2131eff9ce binary
- .git/objects/64/28694338ff041ea1e8b44746a61d79ba0d12ef binary
- .git/objects/64/e722e001bcdd0acfa511d7f176658afcdd07a8 binary
- .git/objects/6d/51fd1f999dec9c763ac06630c5ea3ed71919f5 binary
- .git/objects/6d/7ec056a33b1cbd2a8845e35b71092dac436ae5 binary
- .git/objects/6e/0825817121f8ce2c24adb505367fc6417e88c2 binary
- .git/objects/6f/a9c224f310679b8695f60248ed373d3056ea82 +2/−0
- .git/objects/7c/e104b45e8d0d215ae72f5787ddc5abaad112c7 binary
- .git/objects/83/79ef6f49196d65ef6dbb8044135cd8c465c5e2 binary
- .git/objects/9f/188e32dd3dc00eb4f318a36d6fb8796b08561d binary
- .git/objects/a1/6cdaa5cb651c69be3bbc882a5d318cfc89298f binary
- .git/objects/a1/f0a454435f75be3b739c79538b20ce654874fb binary
- .git/objects/a7/4124a8aaac1737c2ea373ec29171e49da5b523 binary
- .git/objects/ab/2abae0eedde440097437acefcfee6f7d412340 binary
- .git/objects/b0/a8c19ae0e0f3b83424a1e373e480b35d7367e1 +4/−0
- .git/objects/b9/e736a84e2d3b944bd5918811b71a6ea34ad398 binary
- .git/objects/ba/77b722d6557d3eddd05cf97e225246e0811d2c binary
- .git/objects/be/df33621cdf5a3c857be6240ebaf7490c1317c1 binary
- .git/objects/c9/2fcbb8dde5ce9fd7bae7e0600b2e1281a0073b binary
- .git/objects/cb/85c62f8d8c4a948732c7c3c52fd29a99aaee7b binary
- .git/objects/ce/0e5371031772295c58e744c9024571b418d93c binary
- .git/objects/df/084aacab1794b35c3f7dc324f551906ca08b7a binary
- .git/objects/e2/4901fdb01f5c3d9d25720175a6f1890a6f2493 binary
- .git/objects/ef/90e07580fcba7b182ab7d4e92d62d2a25709d5 binary
- .git/objects/f1/63b0e6aee2be8c7e76cbe05c3e3081845a5a07 binary
- .git/objects/f2/588f49ee7d55bc912607a23711cd80d010423e binary
- .git/objects/f4/4e5cbbdb56e9a797445e831d9126a4a0542edf binary
- .git/objects/f7/3bc87cb6e05735bc4cf7fa15e6009e52c1dc86 binary
- .git/objects/fd/13d40b730628c9d443aa07bd05dd55e72a4e32 binary
- .git/objects/pack/pack-2fe5047218c4c2a8c406ce0dbca8bf6fa98a018e.idx binary
- .git/objects/pack/pack-2fe5047218c4c2a8c406ce0dbca8bf6fa98a018e.pack binary
- .git/packed-refs +2/−0
- .git/refs/heads/master +1/−0
- .git/refs/remotes/origin/HEAD +1/−0
- .git/refs/remotes/origin/master +1/−0
- Control/Monad/Imperative.hs +1/−1
- Control/Monad/Imperative/ImperativeMonad.hs +142/−48
- Control/Monad/Imperative/ImperativeOperators.hs +2/−2
- ImperativeHaskell.cabal +1/−1
- ImperativeHaskell/.git/COMMIT_EDITMSG +1/−0
- ImperativeHaskell/.git/HEAD +1/−0
- ImperativeHaskell/.git/config +12/−0
- ImperativeHaskell/.git/description +1/−0
- ImperativeHaskell/.git/hooks/applypatch-msg.sample +15/−0
- ImperativeHaskell/.git/hooks/commit-msg.sample +24/−0
- ImperativeHaskell/.git/hooks/post-commit.sample +8/−0
- ImperativeHaskell/.git/hooks/post-receive.sample +15/−0
- ImperativeHaskell/.git/hooks/post-update.sample +8/−0
- ImperativeHaskell/.git/hooks/pre-applypatch.sample +14/−0
- ImperativeHaskell/.git/hooks/pre-commit.sample +46/−0
- ImperativeHaskell/.git/hooks/pre-rebase.sample +169/−0
- ImperativeHaskell/.git/hooks/prepare-commit-msg.sample +36/−0
- ImperativeHaskell/.git/hooks/update.sample +128/−0
- ImperativeHaskell/.git/index binary
- ImperativeHaskell/.git/info/exclude +6/−0
- ImperativeHaskell/.git/logs/HEAD +13/−0
- ImperativeHaskell/.git/logs/refs/heads/master +13/−0
- ImperativeHaskell/.git/logs/refs/remotes/origin/master +5/−0
- ImperativeHaskell/.git/objects/01/6acde47628279b666290c9dc9191adb7dc653a binary
- ImperativeHaskell/.git/objects/0a/1abd5de3cf5822c055651be49c0740da2dbb10 binary
- ImperativeHaskell/.git/objects/0b/7d578c0025e285b92f790f55ca47ffae3a5fe7 binary
- ImperativeHaskell/.git/objects/11/a89507307aeab1a1284fedbce84afc91a0c992 binary
- ImperativeHaskell/.git/objects/13/61be48fd838579786b5aabfc70fd7a1250dac8 binary
- ImperativeHaskell/.git/objects/13/ea5de1f48b6023a4416b1d1fa8f93b0dfcad6d +2/−0
- ImperativeHaskell/.git/objects/16/fe73c8a57c56fa51da5ed4d259614270f45c44 binary
- ImperativeHaskell/.git/objects/1b/7ae0fd289a218bb3c18711bbb72e0d2f6ff52d binary
- ImperativeHaskell/.git/objects/22/c324eaf52c21034500ee0054f5d7057ed9cb95 +1/−0
- ImperativeHaskell/.git/objects/29/93a9cc0442bb5e0132fbfe285f47d5e224d07e +2/−0
- ImperativeHaskell/.git/objects/32/20183a054c44174eca29bd7e4f74253fa98d1b binary
- ImperativeHaskell/.git/objects/3c/71805404049f0d64221313415cca97d5bfa15f binary
- ImperativeHaskell/.git/objects/3d/f66baae2b65e3cc058cd4b96c923395231ec0d binary
- ImperativeHaskell/.git/objects/3f/f4f6afff27246be0b826adf182e09134a9f0d4 binary
- ImperativeHaskell/.git/objects/4c/ee439117e43cf393fde2d5400edfbd98a2c026 +2/−0
- ImperativeHaskell/.git/objects/4e/c4a30a22a499ca95ef5c826ec86b820ccc17b7 +3/−0
- ImperativeHaskell/.git/objects/50/b441aca5bce63079769ffb015768fdbe213b70 +1/−0
- ImperativeHaskell/.git/objects/52/f49ecd1fcef550c86e7af737810a84c463a5fb binary
- ImperativeHaskell/.git/objects/53/c4b3fec17c1360de0070e11e57d94dfd55ec37 binary
- ImperativeHaskell/.git/objects/56/6b9fea2f24763dd382cdaafb4996b3a6b6dea6 +1/−0
- ImperativeHaskell/.git/objects/58/142aaf2c67098d5485f39d0b2a9b5192e3b454 binary
- ImperativeHaskell/.git/objects/5b/d6e430e9a65225607dd76ca7384e8d15890a03 +3/−0
- ImperativeHaskell/.git/objects/5c/8c8b7980f010d89c33dcc14678cbff61022c84 binary
- ImperativeHaskell/.git/objects/61/553f3af4ea8927fa6e83e4bde2eb2131eff9ce binary
- ImperativeHaskell/.git/objects/64/28694338ff041ea1e8b44746a61d79ba0d12ef binary
- ImperativeHaskell/.git/objects/64/e722e001bcdd0acfa511d7f176658afcdd07a8 binary
- ImperativeHaskell/.git/objects/6d/51fd1f999dec9c763ac06630c5ea3ed71919f5 binary
- ImperativeHaskell/.git/objects/6d/7ec056a33b1cbd2a8845e35b71092dac436ae5 binary
- ImperativeHaskell/.git/objects/6e/0825817121f8ce2c24adb505367fc6417e88c2 binary
- ImperativeHaskell/.git/objects/6f/a9c224f310679b8695f60248ed373d3056ea82 +2/−0
- ImperativeHaskell/.git/objects/70/9c2f6dea81ca7a8c563c05f26d02f15eca7271 binary
- ImperativeHaskell/.git/objects/77/68fc297986b185ee266ce11bc165eb6fd916ee binary
- ImperativeHaskell/.git/objects/7c/e104b45e8d0d215ae72f5787ddc5abaad112c7 binary
- ImperativeHaskell/.git/objects/7e/8229b3957af78a64a8e4e1e40d9af80460afd7 binary
- ImperativeHaskell/.git/objects/83/79ef6f49196d65ef6dbb8044135cd8c465c5e2 binary
- ImperativeHaskell/.git/objects/84/0c0a930e5e486bd75fd9eca9dc33ae03ebad25 binary
- ImperativeHaskell/.git/objects/85/0fdfb3bae5331da0143bc338c9c2fba14c3e60 binary
- ImperativeHaskell/.git/objects/85/2366921764c694dac476d8d1097ff11176675d binary
- ImperativeHaskell/.git/objects/90/635dcf47144403e7f316b098850e9dc98df0bd binary
- ImperativeHaskell/.git/objects/99/e4d79afddff7c3f8c57c975d066e5e20e8823f binary
- ImperativeHaskell/.git/objects/9a/22ba0ce6e904df7c9dda0e39b7961685876555 binary
- ImperativeHaskell/.git/objects/9f/188e32dd3dc00eb4f318a36d6fb8796b08561d binary
- ImperativeHaskell/.git/objects/a1/6cdaa5cb651c69be3bbc882a5d318cfc89298f binary
- ImperativeHaskell/.git/objects/a1/f0a454435f75be3b739c79538b20ce654874fb binary
- ImperativeHaskell/.git/objects/a7/4124a8aaac1737c2ea373ec29171e49da5b523 binary
- ImperativeHaskell/.git/objects/ab/2abae0eedde440097437acefcfee6f7d412340 binary
- ImperativeHaskell/.git/objects/ac/38a6cb36b8beafa100c9937f4b1aa0b17e2986 binary
- ImperativeHaskell/.git/objects/b0/a8c19ae0e0f3b83424a1e373e480b35d7367e1 +4/−0
- ImperativeHaskell/.git/objects/b9/e736a84e2d3b944bd5918811b71a6ea34ad398 binary
- ImperativeHaskell/.git/objects/ba/77b722d6557d3eddd05cf97e225246e0811d2c binary
- ImperativeHaskell/.git/objects/bb/6f7b72c64e9026f7b34e52edf4c2c1676f43e6 binary
- ImperativeHaskell/.git/objects/bc/c99863b67bf2380bc62838d06dc11fc4acab63 binary
- ImperativeHaskell/.git/objects/be/df33621cdf5a3c857be6240ebaf7490c1317c1 binary
- ImperativeHaskell/.git/objects/c2/d854de8f28562adad5fa158dce2e334f0f4358 binary
- ImperativeHaskell/.git/objects/c9/2fcbb8dde5ce9fd7bae7e0600b2e1281a0073b binary
- ImperativeHaskell/.git/objects/cb/85c62f8d8c4a948732c7c3c52fd29a99aaee7b binary
- ImperativeHaskell/.git/objects/ce/0e5371031772295c58e744c9024571b418d93c binary
- ImperativeHaskell/.git/objects/da/7035231ba97f2db1d5a1f2e09c28f9afccfdf1 binary
- ImperativeHaskell/.git/objects/df/084aacab1794b35c3f7dc324f551906ca08b7a binary
- ImperativeHaskell/.git/objects/e2/4901fdb01f5c3d9d25720175a6f1890a6f2493 binary
- ImperativeHaskell/.git/objects/e9/fa7a13df7399b47c5f5dd1b5b67c303bff488c binary
- ImperativeHaskell/.git/objects/ef/17656a91df4096573fc35cca8c6476cd25a17e binary
- ImperativeHaskell/.git/objects/ef/90e07580fcba7b182ab7d4e92d62d2a25709d5 binary
- ImperativeHaskell/.git/objects/f1/63b0e6aee2be8c7e76cbe05c3e3081845a5a07 binary
- ImperativeHaskell/.git/objects/f2/588f49ee7d55bc912607a23711cd80d010423e binary
- ImperativeHaskell/.git/objects/f4/4e5cbbdb56e9a797445e831d9126a4a0542edf binary
- ImperativeHaskell/.git/objects/f7/3bc87cb6e05735bc4cf7fa15e6009e52c1dc86 binary
- ImperativeHaskell/.git/objects/fd/13d40b730628c9d443aa07bd05dd55e72a4e32 binary
- ImperativeHaskell/.git/objects/pack/pack-2fe5047218c4c2a8c406ce0dbca8bf6fa binary
- ImperativeHaskell/.git/packed-refs +2/−0
- ImperativeHaskell/.git/refs/heads/master +1/−0
- ImperativeHaskell/.git/refs/remotes/origin/HEAD +1/−0
- ImperativeHaskell/.git/refs/remotes/origin/master +1/−0
- ImperativeHaskell/Control/Monad/Imperative.hs +13/−0
- ImperativeHaskell/Control/Monad/Imperative/ImperativeMonad.hs +231/−0
- ImperativeHaskell/Control/Monad/Imperative/ImperativeOperators.hs +26/−0
- ImperativeHaskell/ImperativeHaskell.cabal +40/−0
- ImperativeHaskell/LICENSE +320/−0
- ImperativeHaskell/Main.hs +73/−0
- ImperativeHaskell/README +6/−0
- ImperativeHaskell/Setup.hs +2/−0
- Main.hs +24/−15
- README +5/−0
@@ -0,0 +1,1 @@+added two classes to make functions callable in places values are requested, and added a more general return', also changed auto to new
@@ -0,0 +1,1 @@+ref: refs/heads/master
@@ -0,0 +1,12 @@+[core]+ repositoryformatversion = 0+ filemode = true+ bare = false+ logallrefupdates = true+ ignorecase = true+[remote "origin"]+ fetch = +refs/heads/*:refs/remotes/origin/*+ url = git@github.com:mmirman/ImperativeHaskell.git+[branch "master"]+ remote = origin+ merge = refs/heads/master
@@ -0,0 +1,1 @@+Unnamed repository; edit this file 'description' to name the repository.
@@ -0,0 +1,15 @@+#!/bin/sh+#+# An example hook script to check the commit log message taken by+# applypatch from an e-mail message.+#+# The hook should exit with non-zero status after issuing an+# appropriate message if it wants to stop the commit. The hook is+# allowed to edit the commit message file.+#+# To enable this hook, rename this file to "applypatch-msg".++. git-sh-setup+test -x "$GIT_DIR/hooks/commit-msg" &&+ exec "$GIT_DIR/hooks/commit-msg" ${1+"$@"}+:
@@ -0,0 +1,24 @@+#!/bin/sh+#+# An example hook script to check the commit log message.+# Called by "git commit" with one argument, the name of the file+# that has the commit message. The hook should exit with non-zero+# status after issuing an appropriate message if it wants to stop the+# commit. The hook is allowed to edit the commit message file.+#+# To enable this hook, rename this file to "commit-msg".++# Uncomment the below to add a Signed-off-by line to the message.+# Doing this in a hook is a bad idea in general, but the prepare-commit-msg+# hook is more suited to it.+#+# SOB=$(git var GIT_AUTHOR_IDENT | sed -n 's/^\(.*>\).*$/Signed-off-by: \1/p')+# grep -qs "^$SOB" "$1" || echo "$SOB" >> "$1"++# This example catches duplicate Signed-off-by lines.++test "" = "$(grep '^Signed-off-by: ' "$1" |+ sort | uniq -c | sed -e '/^[ ]*1[ ]/d')" || {+ echo >&2 Duplicate Signed-off-by lines.+ exit 1+}
@@ -0,0 +1,8 @@+#!/bin/sh+#+# An example hook script that is called after a successful+# commit is made.+#+# To enable this hook, rename this file to "post-commit".++: Nothing
@@ -0,0 +1,15 @@+#!/bin/sh+#+# An example hook script for the "post-receive" event.+#+# The "post-receive" script is run after receive-pack has accepted a pack+# and the repository has been updated. It is passed arguments in through+# stdin in the form+# <oldrev> <newrev> <refname>+# For example:+# aa453216d1b3e49e7f6f98441fa56946ddcd6a20 68f7abf4e6f922807889f52bc043ecd31b79f814 refs/heads/master+#+# see contrib/hooks/ for a sample, or uncomment the next line and+# rename the file to "post-receive".++#. /usr/share/doc/git-core/contrib/hooks/post-receive-email
@@ -0,0 +1,8 @@+#!/bin/sh+#+# An example hook script to prepare a packed repository for use over+# dumb transports.+#+# To enable this hook, rename this file to "post-update".++exec git update-server-info
@@ -0,0 +1,14 @@+#!/bin/sh+#+# An example hook script to verify what is about to be committed+# by applypatch from an e-mail message.+#+# The hook should exit with non-zero status after issuing an+# appropriate message if it wants to stop the commit.+#+# To enable this hook, rename this file to "pre-applypatch".++. git-sh-setup+test -x "$GIT_DIR/hooks/pre-commit" &&+ exec "$GIT_DIR/hooks/pre-commit" ${1+"$@"}+:
@@ -0,0 +1,46 @@+#!/bin/sh+#+# An example hook script to verify what is about to be committed.+# Called by "git commit" with no arguments. The hook should+# exit with non-zero status after issuing an appropriate message if+# it wants to stop the commit.+#+# To enable this hook, rename this file to "pre-commit".++if git rev-parse --verify HEAD >/dev/null 2>&1+then+ against=HEAD+else+ # Initial commit: diff against an empty tree object+ against=4b825dc642cb6eb9a060e54bf8d69288fbee4904+fi++# If you want to allow non-ascii filenames set this variable to true.+allownonascii=$(git config hooks.allownonascii)++# Cross platform projects tend to avoid non-ascii filenames; prevent+# them from being added to the repository. We exploit the fact that the+# printable range starts at the space character and ends with tilde.+if [ "$allownonascii" != "true" ] &&+ # Note that the use of brackets around a tr range is ok here, (it's+ # even required, for portability to Solaris 10's /usr/bin/tr), since+ # the square bracket bytes happen to fall in the designated range.+ test "$(git diff --cached --name-only --diff-filter=A -z $against |+ LC_ALL=C tr -d '[ -~]\0')"+then+ echo "Error: Attempt to add a non-ascii file name."+ echo+ echo "This can cause problems if you want to work"+ echo "with people on other platforms."+ echo+ echo "To be portable it is advisable to rename the file ..."+ echo+ echo "If you know what you are doing you can disable this"+ echo "check using:"+ echo+ echo " git config hooks.allownonascii true"+ echo+ exit 1+fi++exec git diff-index --check --cached $against --
@@ -0,0 +1,169 @@+#!/bin/sh+#+# Copyright (c) 2006, 2008 Junio C Hamano+#+# The "pre-rebase" hook is run just before "git rebase" starts doing+# its job, and can prevent the command from running by exiting with+# non-zero status.+#+# The hook is called with the following parameters:+#+# $1 -- the upstream the series was forked from.+# $2 -- the branch being rebased (or empty when rebasing the current branch).+#+# This sample shows how to prevent topic branches that are already+# merged to 'next' branch from getting rebased, because allowing it+# would result in rebasing already published history.++publish=next+basebranch="$1"+if test "$#" = 2+then+ topic="refs/heads/$2"+else+ topic=`git symbolic-ref HEAD` ||+ exit 0 ;# we do not interrupt rebasing detached HEAD+fi++case "$topic" in+refs/heads/??/*)+ ;;+*)+ exit 0 ;# we do not interrupt others.+ ;;+esac++# Now we are dealing with a topic branch being rebased+# on top of master. Is it OK to rebase it?++# Does the topic really exist?+git show-ref -q "$topic" || {+ echo >&2 "No such branch $topic"+ exit 1+}++# Is topic fully merged to master?+not_in_master=`git rev-list --pretty=oneline ^master "$topic"`+if test -z "$not_in_master"+then+ echo >&2 "$topic is fully merged to master; better remove it."+ exit 1 ;# we could allow it, but there is no point.+fi++# Is topic ever merged to next? If so you should not be rebasing it.+only_next_1=`git rev-list ^master "^$topic" ${publish} | sort`+only_next_2=`git rev-list ^master ${publish} | sort`+if test "$only_next_1" = "$only_next_2"+then+ not_in_topic=`git rev-list "^$topic" master`+ if test -z "$not_in_topic"+ then+ echo >&2 "$topic is already up-to-date with master"+ exit 1 ;# we could allow it, but there is no point.+ else+ exit 0+ fi+else+ not_in_next=`git rev-list --pretty=oneline ^${publish} "$topic"`+ /opt/local/bin/perl5.12 -e '+ my $topic = $ARGV[0];+ my $msg = "* $topic has commits already merged to public branch:\n";+ my (%not_in_next) = map {+ /^([0-9a-f]+) /;+ ($1 => 1);+ } split(/\n/, $ARGV[1]);+ for my $elem (map {+ /^([0-9a-f]+) (.*)$/;+ [$1 => $2];+ } split(/\n/, $ARGV[2])) {+ if (!exists $not_in_next{$elem->[0]}) {+ if ($msg) {+ print STDERR $msg;+ undef $msg;+ }+ print STDERR " $elem->[1]\n";+ }+ }+ ' "$topic" "$not_in_next" "$not_in_master"+ exit 1+fi++exit 0++################################################################++This sample hook safeguards topic branches that have been+published from being rewound.++The workflow assumed here is:++ * Once a topic branch forks from "master", "master" is never+ merged into it again (either directly or indirectly).++ * Once a topic branch is fully cooked and merged into "master",+ it is deleted. If you need to build on top of it to correct+ earlier mistakes, a new topic branch is created by forking at+ the tip of the "master". This is not strictly necessary, but+ it makes it easier to keep your history simple.++ * Whenever you need to test or publish your changes to topic+ branches, merge them into "next" branch.++The script, being an example, hardcodes the publish branch name+to be "next", but it is trivial to make it configurable via+$GIT_DIR/config mechanism.++With this workflow, you would want to know:++(1) ... if a topic branch has ever been merged to "next". Young+ topic branches can have stupid mistakes you would rather+ clean up before publishing, and things that have not been+ merged into other branches can be easily rebased without+ affecting other people. But once it is published, you would+ not want to rewind it.++(2) ... if a topic branch has been fully merged to "master".+ Then you can delete it. More importantly, you should not+ build on top of it -- other people may already want to+ change things related to the topic as patches against your+ "master", so if you need further changes, it is better to+ fork the topic (perhaps with the same name) afresh from the+ tip of "master".++Let's look at this example:++ o---o---o---o---o---o---o---o---o---o "next"+ / / / /+ / a---a---b A / /+ / / / /+ / / c---c---c---c B /+ / / / \ /+ / / / b---b C \ /+ / / / / \ /+ ---o---o---o---o---o---o---o---o---o---o---o "master"+++A, B and C are topic branches.++ * A has one fix since it was merged up to "next".++ * B has finished. It has been fully merged up to "master" and "next",+ and is ready to be deleted.++ * C has not merged to "next" at all.++We would want to allow C to be rebased, refuse A, and encourage+B to be deleted.++To compute (1):++ git rev-list ^master ^topic next+ git rev-list ^master next++ if these match, topic has not merged in next at all.++To compute (2):++ git rev-list master..topic++ if this is empty, it is fully merged to "master".
@@ -0,0 +1,36 @@+#!/bin/sh+#+# An example hook script to prepare the commit log message.+# Called by "git commit" with the name of the file that has the+# commit message, followed by the description of the commit+# message's source. The hook's purpose is to edit the commit+# message file. If the hook fails with a non-zero status,+# the commit is aborted.+#+# To enable this hook, rename this file to "prepare-commit-msg".++# This hook includes three examples. The first comments out the+# "Conflicts:" part of a merge commit.+#+# The second includes the output of "git diff --name-status -r"+# into the message, just before the "git status" output. It is+# commented because it doesn't cope with --amend or with squashed+# commits.+#+# The third example adds a Signed-off-by line to the message, that can+# still be edited. This is rarely a good idea.++case "$2,$3" in+ merge,)+ /opt/local/bin/perl5.12 -i.bak -ne 's/^/# /, s/^# #/#/ if /^Conflicts/ .. /#/; print' "$1" ;;++# ,|template,)+# /opt/local/bin/perl5.12 -i.bak -pe '+# print "\n" . `git diff --cached --name-status -r`+# if /^#/ && $first++ == 0' "$1" ;;++ *) ;;+esac++# SOB=$(git var GIT_AUTHOR_IDENT | sed -n 's/^\(.*>\).*$/Signed-off-by: \1/p')+# grep -qs "^$SOB" "$1" || echo "$SOB" >> "$1"
@@ -0,0 +1,128 @@+#!/bin/sh+#+# An example hook script to blocks unannotated tags from entering.+# Called by "git receive-pack" with arguments: refname sha1-old sha1-new+#+# To enable this hook, rename this file to "update".+#+# Config+# ------+# hooks.allowunannotated+# This boolean sets whether unannotated tags will be allowed into the+# repository. By default they won't be.+# hooks.allowdeletetag+# This boolean sets whether deleting tags will be allowed in the+# repository. By default they won't be.+# hooks.allowmodifytag+# This boolean sets whether a tag may be modified after creation. By default+# it won't be.+# hooks.allowdeletebranch+# This boolean sets whether deleting branches will be allowed in the+# repository. By default they won't be.+# hooks.denycreatebranch+# This boolean sets whether remotely creating branches will be denied+# in the repository. By default this is allowed.+#++# --- Command line+refname="$1"+oldrev="$2"+newrev="$3"++# --- Safety check+if [ -z "$GIT_DIR" ]; then+ echo "Don't run this script from the command line." >&2+ echo " (if you want, you could supply GIT_DIR then run" >&2+ echo " $0 <ref> <oldrev> <newrev>)" >&2+ exit 1+fi++if [ -z "$refname" -o -z "$oldrev" -o -z "$newrev" ]; then+ echo "Usage: $0 <ref> <oldrev> <newrev>" >&2+ exit 1+fi++# --- Config+allowunannotated=$(git config --bool hooks.allowunannotated)+allowdeletebranch=$(git config --bool hooks.allowdeletebranch)+denycreatebranch=$(git config --bool hooks.denycreatebranch)+allowdeletetag=$(git config --bool hooks.allowdeletetag)+allowmodifytag=$(git config --bool hooks.allowmodifytag)++# check for no description+projectdesc=$(sed -e '1q' "$GIT_DIR/description")+case "$projectdesc" in+"Unnamed repository"* | "")+ echo "*** Project description file hasn't been set" >&2+ exit 1+ ;;+esac++# --- Check types+# if $newrev is 0000...0000, it's a commit to delete a ref.+zero="0000000000000000000000000000000000000000"+if [ "$newrev" = "$zero" ]; then+ newrev_type=delete+else+ newrev_type=$(git cat-file -t $newrev)+fi++case "$refname","$newrev_type" in+ refs/tags/*,commit)+ # un-annotated tag+ short_refname=${refname##refs/tags/}+ if [ "$allowunannotated" != "true" ]; then+ echo "*** The un-annotated tag, $short_refname, is not allowed in this repository" >&2+ echo "*** Use 'git tag [ -a | -s ]' for tags you want to propagate." >&2+ exit 1+ fi+ ;;+ refs/tags/*,delete)+ # delete tag+ if [ "$allowdeletetag" != "true" ]; then+ echo "*** Deleting a tag is not allowed in this repository" >&2+ exit 1+ fi+ ;;+ refs/tags/*,tag)+ # annotated tag+ if [ "$allowmodifytag" != "true" ] && git rev-parse $refname > /dev/null 2>&1+ then+ echo "*** Tag '$refname' already exists." >&2+ echo "*** Modifying a tag is not allowed in this repository." >&2+ exit 1+ fi+ ;;+ refs/heads/*,commit)+ # branch+ if [ "$oldrev" = "$zero" -a "$denycreatebranch" = "true" ]; then+ echo "*** Creating a branch is not allowed in this repository" >&2+ exit 1+ fi+ ;;+ refs/heads/*,delete)+ # delete branch+ if [ "$allowdeletebranch" != "true" ]; then+ echo "*** Deleting a branch is not allowed in this repository" >&2+ exit 1+ fi+ ;;+ refs/remotes/*,commit)+ # tracking branch+ ;;+ refs/remotes/*,delete)+ # delete tracking branch+ if [ "$allowdeletebranch" != "true" ]; then+ echo "*** Deleting a tracking branch is not allowed in this repository" >&2+ exit 1+ fi+ ;;+ *)+ # Anything else (is there anything else?)+ echo "*** Update hook: unknown type of update to ref $refname of type $newrev_type" >&2+ exit 1+ ;;+esac++# --- Finished+exit 0
binary file changed (absent → 728 bytes)
@@ -0,0 +1,6 @@+# git ls-files --others --exclude-from=.git/info/exclude+# Lines that start with '#' are comments.+# For a project mostly in C, the following would be a good set of+# exclude patterns (uncomment them if you want to use them):+# *.[oa]+# *~
@@ -0,0 +1,10 @@+0000000000000000000000000000000000000000 df7defd6c9e46afca38576cb5ebd89d20bad3b3e Matthew Mirman <titaniumeyes@aol.com> 1334780941 -0400 clone: from git@github.com:mmirman/ImperativeHaskell.git+df7defd6c9e46afca38576cb5ebd89d20bad3b3e f44e5cbbdb56e9a797445e831d9126a4a0542edf Matthew Mirman <titaniumeyes@aol.com> 1334781285 -0400 commit: Updated the .cabal+f44e5cbbdb56e9a797445e831d9126a4a0542edf 3c71805404049f0d64221313415cca97d5bfa15f Matthew Mirman <titaniumeyes@aol.com> 1334781305 -0400 commit: Moved the README back to a realistic location+3c71805404049f0d64221313415cca97d5bfa15f 13ea5de1f48b6023a4416b1d1fa8f93b0dfcad6d Matthew Mirman <titaniumeyes@aol.com> 1334782799 -0400 commit: updated the .cabal+13ea5de1f48b6023a4416b1d1fa8f93b0dfcad6d 6fa9c224f310679b8695f60248ed373d3056ea82 Matthew Mirman <titaniumeyes@aol.com> 1334859718 -0400 commit: moved imperative up+6fa9c224f310679b8695f60248ed373d3056ea82 22c324eaf52c21034500ee0054f5d7057ed9cb95 Matthew Mirman <titaniumeyes@aol.com> 1334860946 -0400 commit: fixed ImperativeHaskell.cabal to work+22c324eaf52c21034500ee0054f5d7057ed9cb95 61553f3af4ea8927fa6e83e4bde2eb2131eff9ce Matthew Mirman <titaniumeyes@aol.com> 1334861178 -0400 commit: fixed the .cabal's base to include that base that I am using+61553f3af4ea8927fa6e83e4bde2eb2131eff9ce b0a8c19ae0e0f3b83424a1e373e480b35d7367e1 Matthew Mirman <titaniumeyes@aol.com> 1334862382 -0400 commit: Updaed the .cabal to the current package version+b0a8c19ae0e0f3b83424a1e373e480b35d7367e1 6e0825817121f8ce2c24adb505367fc6417e88c2 Matthew Mirman <titaniumeyes@aol.com> 1334971912 -0400 commit: Updated the readme to point to the relevant blog post+6e0825817121f8ce2c24adb505367fc6417e88c2 df084aacab1794b35c3f7dc324f551906ca08b7a Matthew Mirman <titaniumeyes@aol.com> 1335210914 -0400 commit: added two classes to make functions callable in places values are requested, and added a more general return', also changed auto to new
@@ -0,0 +1,10 @@+0000000000000000000000000000000000000000 df7defd6c9e46afca38576cb5ebd89d20bad3b3e Matthew Mirman <titaniumeyes@aol.com> 1334780941 -0400 clone: from git@github.com:mmirman/ImperativeHaskell.git+df7defd6c9e46afca38576cb5ebd89d20bad3b3e f44e5cbbdb56e9a797445e831d9126a4a0542edf Matthew Mirman <titaniumeyes@aol.com> 1334781285 -0400 commit: Updated the .cabal+f44e5cbbdb56e9a797445e831d9126a4a0542edf 3c71805404049f0d64221313415cca97d5bfa15f Matthew Mirman <titaniumeyes@aol.com> 1334781305 -0400 commit: Moved the README back to a realistic location+3c71805404049f0d64221313415cca97d5bfa15f 13ea5de1f48b6023a4416b1d1fa8f93b0dfcad6d Matthew Mirman <titaniumeyes@aol.com> 1334782799 -0400 commit: updated the .cabal+13ea5de1f48b6023a4416b1d1fa8f93b0dfcad6d 6fa9c224f310679b8695f60248ed373d3056ea82 Matthew Mirman <titaniumeyes@aol.com> 1334859718 -0400 commit: moved imperative up+6fa9c224f310679b8695f60248ed373d3056ea82 22c324eaf52c21034500ee0054f5d7057ed9cb95 Matthew Mirman <titaniumeyes@aol.com> 1334860946 -0400 commit: fixed ImperativeHaskell.cabal to work+22c324eaf52c21034500ee0054f5d7057ed9cb95 61553f3af4ea8927fa6e83e4bde2eb2131eff9ce Matthew Mirman <titaniumeyes@aol.com> 1334861178 -0400 commit: fixed the .cabal's base to include that base that I am using+61553f3af4ea8927fa6e83e4bde2eb2131eff9ce b0a8c19ae0e0f3b83424a1e373e480b35d7367e1 Matthew Mirman <titaniumeyes@aol.com> 1334862382 -0400 commit: Updaed the .cabal to the current package version+b0a8c19ae0e0f3b83424a1e373e480b35d7367e1 6e0825817121f8ce2c24adb505367fc6417e88c2 Matthew Mirman <titaniumeyes@aol.com> 1334971912 -0400 commit: Updated the readme to point to the relevant blog post+6e0825817121f8ce2c24adb505367fc6417e88c2 df084aacab1794b35c3f7dc324f551906ca08b7a Matthew Mirman <titaniumeyes@aol.com> 1335210914 -0400 commit: added two classes to make functions callable in places values are requested, and added a more general return', also changed auto to new
@@ -0,0 +1,3 @@+df7defd6c9e46afca38576cb5ebd89d20bad3b3e 13ea5de1f48b6023a4416b1d1fa8f93b0dfcad6d Matthew Mirman <titaniumeyes@aol.com> 1334782805 -0400 update by push+13ea5de1f48b6023a4416b1d1fa8f93b0dfcad6d 61553f3af4ea8927fa6e83e4bde2eb2131eff9ce Matthew Mirman <titaniumeyes@aol.com> 1334861186 -0400 update by push+61553f3af4ea8927fa6e83e4bde2eb2131eff9ce 6e0825817121f8ce2c24adb505367fc6417e88c2 Matthew Mirman <titaniumeyes@aol.com> 1334971916 -0400 update by push
binary file changed (absent → 85 bytes)
binary file changed (absent → 225 bytes)
binary file changed (absent → 47 bytes)
binary file changed (absent → 226 bytes)
@@ -0,0 +1,2 @@+xAÂ0EYç¾À :Np#!Ä8븢iQq æö3Þî/Þºµ¶8Ä'ßÍ@8aL2"k4!&ÓXÑR©§)¼e·Õqr:eê%Å0«Já§Y0ÏAn;<Äýi_x,{®¾¸¬ËÑì×>wÙ^gÝÚ (ñ¹øéæ!ôµgºý[w·+ýÎ*¼Â/L¶
binary file changed (absent → 262 bytes)
binary file changed (absent → 550 bytes)
@@ -0,0 +1,1 @@+xAn!sæóG,`X$+ÊÑ9ø³ÐÈÈËbáqü>û\ûPUzkUÈxý& ^/ äç´ÁÙÀ %ÀÝd¬ÓêÎ/1®ØIûÙÇcñÚ¸Ù>zðl?åÚ]Xä]êh¼ÑIªðV ¿x|r_ßSo4Yëf¯£ótÐ{Ú×=Sðo*õ¾Ú¥~ãÌÖÝ·ß]I:½ú¸©?r#Uq
binary file changed (absent → 2376 bytes)
binary file changed (absent → 190 bytes)
binary file changed (absent → 93 bytes)
binary file changed (absent → 226 bytes)
@@ -0,0 +1,2 @@+x%ÎÍj1à÷)tË%ñþ@/¹JôìUׯ²elmHÞ¾¦sf>Ëba>?{S(UäÔ£Â[$æ8Ì` ´îü+UÔð¤3`^E"p73_R¡I"°èâVeÏëù¨^µ\Ç1JMèd%cY¶VD4.Ó<=îÒôÍtñág×ÄÇvçÐSa½áÖ!ÿÿ}üC6¾uÃÄ Hz
binary file changed (absent → 568 bytes)
binary file changed (absent → 339 bytes)
@@ -0,0 +1,1 @@+xTïÚ8½ÏHüOí©·l(Tmut·º. XÄUûÑ$±.±#Ç!¥Ûþï; ¬NÚût çÍ7cïµÇàÝÛ¿~{¼~¹¿îüé]» ©ÿyÓûåõÏv«Ýºþ?î¡Â"ápÏX0!ݺ_Xé'ëÆÄ¼ÄBèIt¦îëo&CÍK/Hº.xcØ^$Â(@ù·kriXâü+¥Ï;È93áÎ÷çJÚX_R8K3âVT#¢5VÒhx%YèÍRÂgF+3yUÁL»ãçpc´8ÄqÃס-ýi½ÛXäÈ´:h>#Í9ri>ÂIHÍC-ö á$Li-2ä¤$×i9ØaÊ%`Uì áÏ(·]Écb_Ùøe±©Y`¢P².ȯqä:·¾iÔ=(íèt±ä5»KOHkb½çE¸ÔBHWD¬2*+&T*´I=Gó¨HzÁ×ÙöËýnù¯þzí/·h7 yùWX.¨`X3Is¤"±¸[¿Pÿi6m¨LfÛåÝfÉý>Vþz;ïæþ«Ýzu¿¹ó IE8ÿÚVª4GÈ Iþ¤üjrN1;rjvÀiÜB04JÄÏ»Ü,Qòà%:¡"³Rrbzúý²,½,<¥};Íyÿ£½ê`Ï*Jê5UÖndt°Ò<)BXuö³èTÖîçN»,ëèAzØÅ-¢BîþPµ[tÑó7×` Qn#!yø¡ñÜ µ¥°æ°1ÖüNÖOúµ[Òæý¹Dìèu!Ï+MÛ±õ 3º`0@¬¯¶*óêâí¢ªÅòX±¶ÒV§±+"úÃ7PïIA»Þ<Ý?BÜÕÒ,6AëüoÿäZQ'©T°Nut^u%§ëA57 HZ©¨ù¶ë·®%±èB^n@µ³ÂlKªûÅF¥tm4ºðâêFºi·~Ü
@@ -0,0 +1,3 @@+x¥TmoÚ0Þ×úWøÐOÄÀº µhPÛ Ø4¦}wXø%²hþ}/ ,ME¥I³Åïçî³cec¾|~·Çðj<êòÂïQ)öÖt-|ÄécsôyèLA[#RPxôp?ÿö L+5A¬ñìy³ æJ&" +IÓ{:ÌÝ9¡/;KC4 ÿfJ]!vظÏÀ:ø.â²÷QzCáL¯½uÕ/v(öÕâ=Òú2@¢.R[thômJcs/ýøªÎqJÑÄN¸NRMvÐÖ|( !k$à=X9eÑQ!!÷ãÁ`GQ1O¬h-fÐBedK ñ]¸ÿ¹nØù,ÚJÕ,gõfÁØ´uj!Ã#¬jBÆVB@¾4ìÁí)¼¯T&GècZLÖ;ëÊÉzÅYÅØ·Bª4+eÞ°!V®±Pѡۥ»ÿÄØÆ.ÁÚÉz2)I×bQñh¯,u[ÝÄ´ÿÇòÊJWI4@SÌѤþK,<Âä>ð!\_Ã-|ä÷ú@x¶½áCvÕ4MͰx¢T0´M Ç©N|UÝ:ÞJß§.·ì_¸ÖPÿáÿ£~E¬«®8ÍÅS Þ«®ü¸yú°Ðy(ç"9&Ê÷amÓjëòLzý}p2©$©`Ï~É[
binary file changed (absent → 196 bytes)
binary file changed (absent → 94 bytes)
binary file changed (absent → 80 bytes)
binary file changed (absent → 565 bytes)
binary file changed (absent → 570 bytes)
binary file changed (absent → 192 bytes)
@@ -0,0 +1,2 @@+xÎÝm!Ea?SÅ4Å¥1ÀEF2Ë+Ï:J÷Ùòz><zoB[.2ª&ؤXb^± }¶°:è<{Ö«Úyb2ìLu1½XvÎd©ëõ¤JÍ\BQ|ÈcLº³È?to³óF7iÂ[;:~ñúæñüÌ£ªuÑ_WéC;ÕYÏMÁ¿ÕÇ Zß1YÚtìêäûO
binary file changed (absent → 85 bytes)
binary file changed (absent → 1241 bytes)
binary file changed (absent → 347 bytes)
binary file changed (absent → 242 bytes)
binary file changed (absent → 94 bytes)
binary file changed (absent → 80 bytes)
binary file changed (absent → 226 bytes)
@@ -0,0 +1,4 @@+xËmÃ0DsfÛ ~%+04àc+X.1SètÁ%ä8sxózkUÀÎæM3h4rÈì¨h-é¦`û ôìuFS2Zm8xL®8,1.v.8qtìSfËÉg¸ Xá.·>à"7þk W¸H\ëÞøØïgêís>NÖE'íµVG{h+ÿ >·á3aÂ;H%ÚÇëÉô_OÚWõ^OY
binary file changed (absent → 878 bytes)
binary file changed (absent → 1619 bytes)
binary file changed (absent → 196 bytes)
binary file changed (absent → 48 bytes)
binary file changed (absent → 557 bytes)
binary file changed (absent → 45 bytes)
binary file changed (absent → 243 bytes)
binary file changed (absent → 86 bytes)
binary file changed (absent → 568 bytes)
binary file changed (absent → 226 bytes)
binary file changed (absent → 226 bytes)
binary file changed (absent → 168 bytes)
binary file changed (absent → 47 bytes)
binary file changed (absent → 195 bytes)
binary file changed (absent → 2472 bytes)
binary file changed (absent → 15068 bytes)
@@ -0,0 +1,2 @@+# pack-refs with: peeled +df7defd6c9e46afca38576cb5ebd89d20bad3b3e refs/remotes/origin/master
@@ -0,0 +1,1 @@+df084aacab1794b35c3f7dc324f551906ca08b7a
@@ -0,0 +1,1 @@+ref: refs/remotes/origin/master
@@ -0,0 +1,1 @@+6e0825817121f8ce2c24adb505367fc6417e88c2
@@ -10,5 +10,5 @@ ----------------------------------------------------------------------------- module Control.Monad.Imperative (module X) where -import Control.Monad.Imperative.ImperativeMonad as X +import Control.Monad.Imperative.ImperativeMonad as X hiding (modifyOp, liftOp2) import Control.Monad.Imperative.ImperativeOperators as X
@@ -1,6 +1,11 @@ {-# LANGUAGE GADTs, - EmptyDataDecls + EmptyDataDecls, + GeneralizedNewtypeDeriving, + MultiParamTypeClasses, + FunctionalDependencies, + FlexibleInstances, + UndecidableInstances #-} ----------------------------------------------------------------------------- @@ -9,32 +14,42 @@ -- Maintainer : Matthew Mirman <mmirman@andrew.cmu.edu> -- Stability : experimental -- Portability : GADTs, EmptyDataDecls +-- License : GNU-3 -- Description : A module for Imperative haskell code. --- License : GNUv3 -- ----------------------------------------------------------------------------- module Control.Monad.Imperative.ImperativeMonad ( modifyOp , if' - , for - , break - , continue + , for' + , while' + , break' + , continue' + , return' , returnV + , returnF , function + , new , auto , runImperative + , liftOp , liftOp2 - , prim + , liftOp3 + , liftOp4 + , liftOp5 + , V(Lit) , returnF , (=:) , (&) ) where -import Prelude hiding (break) import Control.Monad.Cont import Control.Monad.Reader import Data.IORef +newtype MIO r a = MIO { getMIO :: ReaderT (Control r) (ContT r IO) a } + deriving (Monad, MonadCont) + data Var data Val data Comp @@ -45,91 +60,170 @@ , controlReturn:: r -> MIO r () } +-- | @'returnF' value@ acts like the imperative return, where +-- if called, it will exit the current function and place the +-- returned value into the current continuation. Note, this +-- doesn't work inside of loops. Inside of loops, we need +-- 'returnV' returnF :: V a b b -> MIO b b -returnF v = do - v' <- val v +returnF v = MIO $ do + v' <- getMIO $ val v a <- ask case a of - InLoop _ _ ret -> ret v' + InLoop _ _ ret -> getMIO $ ret v' InFunction ret -> lift $ ret v' return v' + +-- | @'returnV' value@ acts like the imperative return, where +-- if called, it will exit the current function and place the +-- returned value into the current continuation. Note, this +-- doesn't work as a last function call. +returnV :: V a b b -> MIO b () +returnV a = returnF a >> return () +class Returnable b r where + -- | @'return''@ can act as returnF or returnV depending on use + -- if it does not work, it is likely that type inference + -- could not figure out a sensible alternative. + return' :: V a b b -> MIO b r + +instance Returnable b () where + return' a = returnV a + +instance Returnable b b where + return' a = returnF a + + runImperative :: MIO a a -> IO a -runImperative foo = runContT (callCC $ \ret -> runReaderT foo $ InFunction ret) return +runImperative foo = do + a <- runContT (callCC $ \ret -> runReaderT (getMIO foo) $ InFunction ret) return + return a +-- | @'function' foo@ takes an ImperativeMonad action and removes it from it's +-- specific function context, specifically making it applicable +-- in the body of other functions. function :: MIO a a -> MIO b a -function = liftIO . runImperative +function = MIO . liftIO . runImperative -break :: MIO a () -break = do - a <- ask +-- | @'break'@ exists the current loop. +break' :: MIO a () +break' = do + a <- MIO $ ask case a of InLoop br _ _ -> br _ -> return () - -continue :: MIO a () -continue = do - a <- ask + +-- | @'continue'@ continues the current loop, passing over +-- any control flow that is defined. +continue' :: MIO a () +continue' = do + a <- MIO $ ask case a of InLoop _ con _ -> con _ -> return () -type MIO r a = ReaderT (Control r) (ContT r IO) a - data V b r a where R :: IORef a -> V Var r a - L :: a -> V Val r a + Lit :: a -> V Val r a C :: MIO r (V b r a) -> V Comp r a -returnV a = returnF a >> return () val :: V b r a -> MIO r a val v = case v of - R r -> liftIO $ readIORef r - L v -> return v + R r -> MIO $ liftIO $ readIORef r + Lit v -> return v C m -> val =<< m +-- | @('&')a@ gets a reference/pointer to the variable specified (&) :: V Var r a -> V Var s a (&) (R a) = R a -auto :: a -> MIO r (V Var r a) -auto a = do - r <- liftIO $ newIORef a - return $ R r +-- | @auto@ should just be used where the +-- type can be automatically infered and we don't need an initial value +auto = undefined -prim :: a -> V Val r a -prim a = L a +-- | @new@ constructs a new reference object with the value specified +new :: a -> MIO r (V Var r a) +new a = do + r <- MIO $ liftIO $ newIORef a + return $ R r infixr 0 =: -(=:) :: V Var r a -> V b r a -> MIO r () -(=:) (R ar) br = do - b <- val br - liftIO $ writeIORef ar b -for :: (MIO r irr1, V b r Bool, MIO r irr2) -> MIO r () -> MIO r () -for (init, check, incr) body = init >> for' - where for' = do +class Assignable val where + -- | @var '=:' value@ simply rewrites whatever + -- is in @var@ with whatever @value@ is. + (=:) :: V Var r a -> val r a -> MIO r () + +instance Assignable (V b) where + (=:) (R ar) br = MIO $ do + b <- getMIO $ val br + liftIO $ writeIORef ar b + +instance Assignable MIO where + (=:) a br = do + b <- br + a =: Lit b + +-- | @'for'(init, check, incr)@ acts like the usual imperative for loop +for' :: (MIO r irr1, V b r Bool, MIO r irr2) -> MIO r () -> MIO r () +for' (init, check, incr) body = init >> for_r + where for_r = do do_comp <- val check when do_comp $ callCC $ \break_foo -> do - callCC $ \continue_foo -> do - flip withReaderT body $ \inbod -> + callCC $ \continue_foo -> MIO $ do + flip withReaderT (getMIO body) $ \inbod -> InLoop (break_foo ()) (continue_foo ()) (controlReturn inbod) incr - for' + for_r +-- | @'while'(check)@ acts like the usual imperative while +while' :: V b r Bool -> MIO r () -> MIO r () +while' check = for'(return (), check, return () ) + +-- | @'if'(check) m@ only executes m if the check is true. +-- it is specifically value in it's argument. if' :: V b r Bool -> MIO r () -> MIO r () if' b m = do v <- val b when v m +-- | @'modifyOp' f@ makes a modify operator out of a binary +-- haskell function modifyOp :: (a->b->a) -> V Var r a -> V k r b -> MIO r () -modifyOp op (R ar) br = do - b <- val br +modifyOp op (R ar) br = MIO $ do + b <- getMIO $ val br liftIO $ modifyIORef ar (\v -> op v b) -liftOp2 :: (t -> t' -> a) -> V b r t -> V b' r t' -> V Comp r a -liftOp2 foo ar br = C $ do - a <- val ar - b <- val br - return $ prim $ foo a b +-- | @'liftOp' f@ turns a pure function into one which +-- gets the values out of it's arguments +liftOp foo a = C $ do + a' <- val a + return $ Lit $ foo a' + +liftOp2 foo a1 a2 = C $ do + a1' <- val a1 + a2' <- val a2 + return $ Lit $ foo a1' a2' + +liftOp3 foo v1 v2 v3 = C $ do + v1' <- val v1 + v2' <- val v2 + v3' <- val v3 + return $ Lit $ foo v1' v2' v3' + +liftOp4 foo v1 v2 v3 v4 = C $ do + v1' <- val v1 + v2' <- val v2 + v3' <- val v3 + v4' <- val v4 + return $ Lit $ foo v1' v2' v3' v4' + +liftOp5 foo v1 v2 v3 v4 v5 = C $ do + v1' <- val v1 + v2' <- val v2 + v3' <- val v3 + v4' <- val v4 + v5' <- val v5 + return $ Lit $ foo v1' v2' v3' v5' v4'
@@ -7,13 +7,13 @@ -- Maintainer : Matthew Mirman <mmirman@andrew.cmu.edu> -- Stability : experimental -- Portability : NoMonomorphismRestriction +-- License : GNU-3 -- Description : Some predefined operators for the imperative monad. --- License : GNUv3 -- ----------------------------------------------------------------------------- module Control.Monad.Imperative.ImperativeOperators where -import Control.Monad.Imperative.ImperativeMonad +import Control.Monad.Imperative.ImperativeMonad (modifyOp, liftOp2) (+=:) = modifyOp (+)
@@ -1,5 +1,5 @@ Name: ImperativeHaskell-Version: 0.1.0.1+Version: 0.2.0.0 Description: A monad that uses GADTs and continuations to replicate what it is like to program in an imperative language like C or Java
@@ -0,0 +1,1 @@+updated the documentation
@@ -0,0 +1,1 @@+ref: refs/heads/master
@@ -0,0 +1,12 @@+[core]+ repositoryformatversion = 0+ filemode = true+ bare = false+ logallrefupdates = true+ ignorecase = true+[remote "origin"]+ fetch = +refs/heads/*:refs/remotes/origin/*+ url = git@github.com:mmirman/ImperativeHaskell.git+[branch "master"]+ remote = origin+ merge = refs/heads/master
@@ -0,0 +1,1 @@+Unnamed repository; edit this file 'description' to name the repository.
@@ -0,0 +1,15 @@+#!/bin/sh+#+# An example hook script to check the commit log message taken by+# applypatch from an e-mail message.+#+# The hook should exit with non-zero status after issuing an+# appropriate message if it wants to stop the commit. The hook is+# allowed to edit the commit message file.+#+# To enable this hook, rename this file to "applypatch-msg".++. git-sh-setup+test -x "$GIT_DIR/hooks/commit-msg" &&+ exec "$GIT_DIR/hooks/commit-msg" ${1+"$@"}+:
@@ -0,0 +1,24 @@+#!/bin/sh+#+# An example hook script to check the commit log message.+# Called by "git commit" with one argument, the name of the file+# that has the commit message. The hook should exit with non-zero+# status after issuing an appropriate message if it wants to stop the+# commit. The hook is allowed to edit the commit message file.+#+# To enable this hook, rename this file to "commit-msg".++# Uncomment the below to add a Signed-off-by line to the message.+# Doing this in a hook is a bad idea in general, but the prepare-commit-msg+# hook is more suited to it.+#+# SOB=$(git var GIT_AUTHOR_IDENT | sed -n 's/^\(.*>\).*$/Signed-off-by: \1/p')+# grep -qs "^$SOB" "$1" || echo "$SOB" >> "$1"++# This example catches duplicate Signed-off-by lines.++test "" = "$(grep '^Signed-off-by: ' "$1" |+ sort | uniq -c | sed -e '/^[ ]*1[ ]/d')" || {+ echo >&2 Duplicate Signed-off-by lines.+ exit 1+}
@@ -0,0 +1,8 @@+#!/bin/sh+#+# An example hook script that is called after a successful+# commit is made.+#+# To enable this hook, rename this file to "post-commit".++: Nothing
@@ -0,0 +1,15 @@+#!/bin/sh+#+# An example hook script for the "post-receive" event.+#+# The "post-receive" script is run after receive-pack has accepted a pack+# and the repository has been updated. It is passed arguments in through+# stdin in the form+# <oldrev> <newrev> <refname>+# For example:+# aa453216d1b3e49e7f6f98441fa56946ddcd6a20 68f7abf4e6f922807889f52bc043ecd31b79f814 refs/heads/master+#+# see contrib/hooks/ for a sample, or uncomment the next line and+# rename the file to "post-receive".++#. /usr/share/doc/git-core/contrib/hooks/post-receive-email
@@ -0,0 +1,8 @@+#!/bin/sh+#+# An example hook script to prepare a packed repository for use over+# dumb transports.+#+# To enable this hook, rename this file to "post-update".++exec git update-server-info
@@ -0,0 +1,14 @@+#!/bin/sh+#+# An example hook script to verify what is about to be committed+# by applypatch from an e-mail message.+#+# The hook should exit with non-zero status after issuing an+# appropriate message if it wants to stop the commit.+#+# To enable this hook, rename this file to "pre-applypatch".++. git-sh-setup+test -x "$GIT_DIR/hooks/pre-commit" &&+ exec "$GIT_DIR/hooks/pre-commit" ${1+"$@"}+:
@@ -0,0 +1,46 @@+#!/bin/sh+#+# An example hook script to verify what is about to be committed.+# Called by "git commit" with no arguments. The hook should+# exit with non-zero status after issuing an appropriate message if+# it wants to stop the commit.+#+# To enable this hook, rename this file to "pre-commit".++if git rev-parse --verify HEAD >/dev/null 2>&1+then+ against=HEAD+else+ # Initial commit: diff against an empty tree object+ against=4b825dc642cb6eb9a060e54bf8d69288fbee4904+fi++# If you want to allow non-ascii filenames set this variable to true.+allownonascii=$(git config hooks.allownonascii)++# Cross platform projects tend to avoid non-ascii filenames; prevent+# them from being added to the repository. We exploit the fact that the+# printable range starts at the space character and ends with tilde.+if [ "$allownonascii" != "true" ] &&+ # Note that the use of brackets around a tr range is ok here, (it's+ # even required, for portability to Solaris 10's /usr/bin/tr), since+ # the square bracket bytes happen to fall in the designated range.+ test "$(git diff --cached --name-only --diff-filter=A -z $against |+ LC_ALL=C tr -d '[ -~]\0')"+then+ echo "Error: Attempt to add a non-ascii file name."+ echo+ echo "This can cause problems if you want to work"+ echo "with people on other platforms."+ echo+ echo "To be portable it is advisable to rename the file ..."+ echo+ echo "If you know what you are doing you can disable this"+ echo "check using:"+ echo+ echo " git config hooks.allownonascii true"+ echo+ exit 1+fi++exec git diff-index --check --cached $against --
@@ -0,0 +1,169 @@+#!/bin/sh+#+# Copyright (c) 2006, 2008 Junio C Hamano+#+# The "pre-rebase" hook is run just before "git rebase" starts doing+# its job, and can prevent the command from running by exiting with+# non-zero status.+#+# The hook is called with the following parameters:+#+# $1 -- the upstream the series was forked from.+# $2 -- the branch being rebased (or empty when rebasing the current branch).+#+# This sample shows how to prevent topic branches that are already+# merged to 'next' branch from getting rebased, because allowing it+# would result in rebasing already published history.++publish=next+basebranch="$1"+if test "$#" = 2+then+ topic="refs/heads/$2"+else+ topic=`git symbolic-ref HEAD` ||+ exit 0 ;# we do not interrupt rebasing detached HEAD+fi++case "$topic" in+refs/heads/??/*)+ ;;+*)+ exit 0 ;# we do not interrupt others.+ ;;+esac++# Now we are dealing with a topic branch being rebased+# on top of master. Is it OK to rebase it?++# Does the topic really exist?+git show-ref -q "$topic" || {+ echo >&2 "No such branch $topic"+ exit 1+}++# Is topic fully merged to master?+not_in_master=`git rev-list --pretty=oneline ^master "$topic"`+if test -z "$not_in_master"+then+ echo >&2 "$topic is fully merged to master; better remove it."+ exit 1 ;# we could allow it, but there is no point.+fi++# Is topic ever merged to next? If so you should not be rebasing it.+only_next_1=`git rev-list ^master "^$topic" ${publish} | sort`+only_next_2=`git rev-list ^master ${publish} | sort`+if test "$only_next_1" = "$only_next_2"+then+ not_in_topic=`git rev-list "^$topic" master`+ if test -z "$not_in_topic"+ then+ echo >&2 "$topic is already up-to-date with master"+ exit 1 ;# we could allow it, but there is no point.+ else+ exit 0+ fi+else+ not_in_next=`git rev-list --pretty=oneline ^${publish} "$topic"`+ /opt/local/bin/perl5.12 -e '+ my $topic = $ARGV[0];+ my $msg = "* $topic has commits already merged to public branch:\n";+ my (%not_in_next) = map {+ /^([0-9a-f]+) /;+ ($1 => 1);+ } split(/\n/, $ARGV[1]);+ for my $elem (map {+ /^([0-9a-f]+) (.*)$/;+ [$1 => $2];+ } split(/\n/, $ARGV[2])) {+ if (!exists $not_in_next{$elem->[0]}) {+ if ($msg) {+ print STDERR $msg;+ undef $msg;+ }+ print STDERR " $elem->[1]\n";+ }+ }+ ' "$topic" "$not_in_next" "$not_in_master"+ exit 1+fi++exit 0++################################################################++This sample hook safeguards topic branches that have been+published from being rewound.++The workflow assumed here is:++ * Once a topic branch forks from "master", "master" is never+ merged into it again (either directly or indirectly).++ * Once a topic branch is fully cooked and merged into "master",+ it is deleted. If you need to build on top of it to correct+ earlier mistakes, a new topic branch is created by forking at+ the tip of the "master". This is not strictly necessary, but+ it makes it easier to keep your history simple.++ * Whenever you need to test or publish your changes to topic+ branches, merge them into "next" branch.++The script, being an example, hardcodes the publish branch name+to be "next", but it is trivial to make it configurable via+$GIT_DIR/config mechanism.++With this workflow, you would want to know:++(1) ... if a topic branch has ever been merged to "next". Young+ topic branches can have stupid mistakes you would rather+ clean up before publishing, and things that have not been+ merged into other branches can be easily rebased without+ affecting other people. But once it is published, you would+ not want to rewind it.++(2) ... if a topic branch has been fully merged to "master".+ Then you can delete it. More importantly, you should not+ build on top of it -- other people may already want to+ change things related to the topic as patches against your+ "master", so if you need further changes, it is better to+ fork the topic (perhaps with the same name) afresh from the+ tip of "master".++Let's look at this example:++ o---o---o---o---o---o---o---o---o---o "next"+ / / / /+ / a---a---b A / /+ / / / /+ / / c---c---c---c B /+ / / / \ /+ / / / b---b C \ /+ / / / / \ /+ ---o---o---o---o---o---o---o---o---o---o---o "master"+++A, B and C are topic branches.++ * A has one fix since it was merged up to "next".++ * B has finished. It has been fully merged up to "master" and "next",+ and is ready to be deleted.++ * C has not merged to "next" at all.++We would want to allow C to be rebased, refuse A, and encourage+B to be deleted.++To compute (1):++ git rev-list ^master ^topic next+ git rev-list ^master next++ if these match, topic has not merged in next at all.++To compute (2):++ git rev-list master..topic++ if this is empty, it is fully merged to "master".
@@ -0,0 +1,36 @@+#!/bin/sh+#+# An example hook script to prepare the commit log message.+# Called by "git commit" with the name of the file that has the+# commit message, followed by the description of the commit+# message's source. The hook's purpose is to edit the commit+# message file. If the hook fails with a non-zero status,+# the commit is aborted.+#+# To enable this hook, rename this file to "prepare-commit-msg".++# This hook includes three examples. The first comments out the+# "Conflicts:" part of a merge commit.+#+# The second includes the output of "git diff --name-status -r"+# into the message, just before the "git status" output. It is+# commented because it doesn't cope with --amend or with squashed+# commits.+#+# The third example adds a Signed-off-by line to the message, that can+# still be edited. This is rarely a good idea.++case "$2,$3" in+ merge,)+ /opt/local/bin/perl5.12 -i.bak -ne 's/^/# /, s/^# #/#/ if /^Conflicts/ .. /#/; print' "$1" ;;++# ,|template,)+# /opt/local/bin/perl5.12 -i.bak -pe '+# print "\n" . `git diff --cached --name-status -r`+# if /^#/ && $first++ == 0' "$1" ;;++ *) ;;+esac++# SOB=$(git var GIT_AUTHOR_IDENT | sed -n 's/^\(.*>\).*$/Signed-off-by: \1/p')+# grep -qs "^$SOB" "$1" || echo "$SOB" >> "$1"
@@ -0,0 +1,128 @@+#!/bin/sh+#+# An example hook script to blocks unannotated tags from entering.+# Called by "git receive-pack" with arguments: refname sha1-old sha1-new+#+# To enable this hook, rename this file to "update".+#+# Config+# ------+# hooks.allowunannotated+# This boolean sets whether unannotated tags will be allowed into the+# repository. By default they won't be.+# hooks.allowdeletetag+# This boolean sets whether deleting tags will be allowed in the+# repository. By default they won't be.+# hooks.allowmodifytag+# This boolean sets whether a tag may be modified after creation. By default+# it won't be.+# hooks.allowdeletebranch+# This boolean sets whether deleting branches will be allowed in the+# repository. By default they won't be.+# hooks.denycreatebranch+# This boolean sets whether remotely creating branches will be denied+# in the repository. By default this is allowed.+#++# --- Command line+refname="$1"+oldrev="$2"+newrev="$3"++# --- Safety check+if [ -z "$GIT_DIR" ]; then+ echo "Don't run this script from the command line." >&2+ echo " (if you want, you could supply GIT_DIR then run" >&2+ echo " $0 <ref> <oldrev> <newrev>)" >&2+ exit 1+fi++if [ -z "$refname" -o -z "$oldrev" -o -z "$newrev" ]; then+ echo "Usage: $0 <ref> <oldrev> <newrev>" >&2+ exit 1+fi++# --- Config+allowunannotated=$(git config --bool hooks.allowunannotated)+allowdeletebranch=$(git config --bool hooks.allowdeletebranch)+denycreatebranch=$(git config --bool hooks.denycreatebranch)+allowdeletetag=$(git config --bool hooks.allowdeletetag)+allowmodifytag=$(git config --bool hooks.allowmodifytag)++# check for no description+projectdesc=$(sed -e '1q' "$GIT_DIR/description")+case "$projectdesc" in+"Unnamed repository"* | "")+ echo "*** Project description file hasn't been set" >&2+ exit 1+ ;;+esac++# --- Check types+# if $newrev is 0000...0000, it's a commit to delete a ref.+zero="0000000000000000000000000000000000000000"+if [ "$newrev" = "$zero" ]; then+ newrev_type=delete+else+ newrev_type=$(git cat-file -t $newrev)+fi++case "$refname","$newrev_type" in+ refs/tags/*,commit)+ # un-annotated tag+ short_refname=${refname##refs/tags/}+ if [ "$allowunannotated" != "true" ]; then+ echo "*** The un-annotated tag, $short_refname, is not allowed in this repository" >&2+ echo "*** Use 'git tag [ -a | -s ]' for tags you want to propagate." >&2+ exit 1+ fi+ ;;+ refs/tags/*,delete)+ # delete tag+ if [ "$allowdeletetag" != "true" ]; then+ echo "*** Deleting a tag is not allowed in this repository" >&2+ exit 1+ fi+ ;;+ refs/tags/*,tag)+ # annotated tag+ if [ "$allowmodifytag" != "true" ] && git rev-parse $refname > /dev/null 2>&1+ then+ echo "*** Tag '$refname' already exists." >&2+ echo "*** Modifying a tag is not allowed in this repository." >&2+ exit 1+ fi+ ;;+ refs/heads/*,commit)+ # branch+ if [ "$oldrev" = "$zero" -a "$denycreatebranch" = "true" ]; then+ echo "*** Creating a branch is not allowed in this repository" >&2+ exit 1+ fi+ ;;+ refs/heads/*,delete)+ # delete branch+ if [ "$allowdeletebranch" != "true" ]; then+ echo "*** Deleting a branch is not allowed in this repository" >&2+ exit 1+ fi+ ;;+ refs/remotes/*,commit)+ # tracking branch+ ;;+ refs/remotes/*,delete)+ # delete tracking branch+ if [ "$allowdeletebranch" != "true" ]; then+ echo "*** Deleting a tracking branch is not allowed in this repository" >&2+ exit 1+ fi+ ;;+ *)+ # Anything else (is there anything else?)+ echo "*** Update hook: unknown type of update to ref $refname of type $newrev_type" >&2+ exit 1+ ;;+esac++# --- Finished+exit 0
binary file changed (absent → 728 bytes)
@@ -0,0 +1,6 @@+# git ls-files --others --exclude-from=.git/info/exclude+# Lines that start with '#' are comments.+# For a project mostly in C, the following would be a good set of+# exclude patterns (uncomment them if you want to use them):+# *.[oa]+# *~
@@ -0,0 +1,13 @@+0000000000000000000000000000000000000000 df7defd6c9e46afca38576cb5ebd89d20bad3b3e Matthew Mirman <titaniumeyes@aol.com> 1334780941 -0400 clone: from git@github.com:mmirman/ImperativeHaskell.git+df7defd6c9e46afca38576cb5ebd89d20bad3b3e f44e5cbbdb56e9a797445e831d9126a4a0542edf Matthew Mirman <titaniumeyes@aol.com> 1334781285 -0400 commit: Updated the .cabal+f44e5cbbdb56e9a797445e831d9126a4a0542edf 3c71805404049f0d64221313415cca97d5bfa15f Matthew Mirman <titaniumeyes@aol.com> 1334781305 -0400 commit: Moved the README back to a realistic location+3c71805404049f0d64221313415cca97d5bfa15f 13ea5de1f48b6023a4416b1d1fa8f93b0dfcad6d Matthew Mirman <titaniumeyes@aol.com> 1334782799 -0400 commit: updated the .cabal+13ea5de1f48b6023a4416b1d1fa8f93b0dfcad6d 6fa9c224f310679b8695f60248ed373d3056ea82 Matthew Mirman <titaniumeyes@aol.com> 1334859718 -0400 commit: moved imperative up+6fa9c224f310679b8695f60248ed373d3056ea82 22c324eaf52c21034500ee0054f5d7057ed9cb95 Matthew Mirman <titaniumeyes@aol.com> 1334860946 -0400 commit: fixed ImperativeHaskell.cabal to work+22c324eaf52c21034500ee0054f5d7057ed9cb95 61553f3af4ea8927fa6e83e4bde2eb2131eff9ce Matthew Mirman <titaniumeyes@aol.com> 1334861178 -0400 commit: fixed the .cabal's base to include that base that I am using+61553f3af4ea8927fa6e83e4bde2eb2131eff9ce b0a8c19ae0e0f3b83424a1e373e480b35d7367e1 Matthew Mirman <titaniumeyes@aol.com> 1334862382 -0400 commit: Updaed the .cabal to the current package version+b0a8c19ae0e0f3b83424a1e373e480b35d7367e1 6e0825817121f8ce2c24adb505367fc6417e88c2 Matthew Mirman <titaniumeyes@aol.com> 1334971912 -0400 commit: Updated the readme to point to the relevant blog post+6e0825817121f8ce2c24adb505367fc6417e88c2 df084aacab1794b35c3f7dc324f551906ca08b7a Matthew Mirman <titaniumeyes@aol.com> 1335210914 -0400 commit: added two classes to make functions callable in places values are requested, and added a more general return', also changed auto to new+df084aacab1794b35c3f7dc324f551906ca08b7a 852366921764c694dac476d8d1097ff11176675d Matthew Mirman <titaniumeyes@aol.com> 1335211105 -0400 commit: fixed the .cabal and the headers to reflect the changes+852366921764c694dac476d8d1097ff11176675d 2993a9cc0442bb5e0132fbfe285f47d5e224d07e Matthew Mirman <titaniumeyes@aol.com> 1335211162 -0400 commit: removed the extra returnF export+2993a9cc0442bb5e0132fbfe285f47d5e224d07e 850fdfb3bae5331da0143bc338c9c2fba14c3e60 Matthew Mirman <titaniumeyes@aol.com> 1335211384 -0400 commit: updated the documentation
@@ -0,0 +1,13 @@+0000000000000000000000000000000000000000 df7defd6c9e46afca38576cb5ebd89d20bad3b3e Matthew Mirman <titaniumeyes@aol.com> 1334780941 -0400 clone: from git@github.com:mmirman/ImperativeHaskell.git+df7defd6c9e46afca38576cb5ebd89d20bad3b3e f44e5cbbdb56e9a797445e831d9126a4a0542edf Matthew Mirman <titaniumeyes@aol.com> 1334781285 -0400 commit: Updated the .cabal+f44e5cbbdb56e9a797445e831d9126a4a0542edf 3c71805404049f0d64221313415cca97d5bfa15f Matthew Mirman <titaniumeyes@aol.com> 1334781305 -0400 commit: Moved the README back to a realistic location+3c71805404049f0d64221313415cca97d5bfa15f 13ea5de1f48b6023a4416b1d1fa8f93b0dfcad6d Matthew Mirman <titaniumeyes@aol.com> 1334782799 -0400 commit: updated the .cabal+13ea5de1f48b6023a4416b1d1fa8f93b0dfcad6d 6fa9c224f310679b8695f60248ed373d3056ea82 Matthew Mirman <titaniumeyes@aol.com> 1334859718 -0400 commit: moved imperative up+6fa9c224f310679b8695f60248ed373d3056ea82 22c324eaf52c21034500ee0054f5d7057ed9cb95 Matthew Mirman <titaniumeyes@aol.com> 1334860946 -0400 commit: fixed ImperativeHaskell.cabal to work+22c324eaf52c21034500ee0054f5d7057ed9cb95 61553f3af4ea8927fa6e83e4bde2eb2131eff9ce Matthew Mirman <titaniumeyes@aol.com> 1334861178 -0400 commit: fixed the .cabal's base to include that base that I am using+61553f3af4ea8927fa6e83e4bde2eb2131eff9ce b0a8c19ae0e0f3b83424a1e373e480b35d7367e1 Matthew Mirman <titaniumeyes@aol.com> 1334862382 -0400 commit: Updaed the .cabal to the current package version+b0a8c19ae0e0f3b83424a1e373e480b35d7367e1 6e0825817121f8ce2c24adb505367fc6417e88c2 Matthew Mirman <titaniumeyes@aol.com> 1334971912 -0400 commit: Updated the readme to point to the relevant blog post+6e0825817121f8ce2c24adb505367fc6417e88c2 df084aacab1794b35c3f7dc324f551906ca08b7a Matthew Mirman <titaniumeyes@aol.com> 1335210914 -0400 commit: added two classes to make functions callable in places values are requested, and added a more general return', also changed auto to new+df084aacab1794b35c3f7dc324f551906ca08b7a 852366921764c694dac476d8d1097ff11176675d Matthew Mirman <titaniumeyes@aol.com> 1335211105 -0400 commit: fixed the .cabal and the headers to reflect the changes+852366921764c694dac476d8d1097ff11176675d 2993a9cc0442bb5e0132fbfe285f47d5e224d07e Matthew Mirman <titaniumeyes@aol.com> 1335211162 -0400 commit: removed the extra returnF export+2993a9cc0442bb5e0132fbfe285f47d5e224d07e 850fdfb3bae5331da0143bc338c9c2fba14c3e60 Matthew Mirman <titaniumeyes@aol.com> 1335211384 -0400 commit: updated the documentation
@@ -0,0 +1,5 @@+df7defd6c9e46afca38576cb5ebd89d20bad3b3e 13ea5de1f48b6023a4416b1d1fa8f93b0dfcad6d Matthew Mirman <titaniumeyes@aol.com> 1334782805 -0400 update by push+13ea5de1f48b6023a4416b1d1fa8f93b0dfcad6d 61553f3af4ea8927fa6e83e4bde2eb2131eff9ce Matthew Mirman <titaniumeyes@aol.com> 1334861186 -0400 update by push+61553f3af4ea8927fa6e83e4bde2eb2131eff9ce 6e0825817121f8ce2c24adb505367fc6417e88c2 Matthew Mirman <titaniumeyes@aol.com> 1334971916 -0400 update by push+6e0825817121f8ce2c24adb505367fc6417e88c2 2993a9cc0442bb5e0132fbfe285f47d5e224d07e Matthew Mirman <titaniumeyes@aol.com> 1335211168 -0400 update by push+2993a9cc0442bb5e0132fbfe285f47d5e224d07e 850fdfb3bae5331da0143bc338c9c2fba14c3e60 Matthew Mirman <titaniumeyes@aol.com> 1335211394 -0400 update by push
binary file changed (absent → 85 bytes)
binary file changed (absent → 225 bytes)
binary file changed (absent → 47 bytes)
binary file changed (absent → 226 bytes)
binary file changed (absent → 47 bytes)
@@ -0,0 +1,2 @@+xAÂ0EYç¾À :Np#!Ä8븢iQq æö3Þî/Þºµ¶8Ä'ßÍ@8aL2"k4!&ÓXÑR©§)¼e·Õqr:eê%Å0«Já§Y0ÏAn;<Äýi_x,{®¾¸¬ËÑì×>wÙ^gÝÚ (ñ¹øéæ!ôµgºý[w·+ýÎ*¼Â/L¶
binary file changed (absent → 262 bytes)
binary file changed (absent → 550 bytes)
@@ -0,0 +1,1 @@+xAn!sæóG,`X$+ÊÑ9ø³ÐÈÈËbáqü>û\ûPUzkUÈxý& ^/ äç´ÁÙÀ %ÀÝd¬ÓêÎ/1®ØIûÙÇcñÚ¸Ù>zðl?åÚ]Xä]êh¼ÑIªðV ¿x|r_ßSo4Yëf¯£ótÐ{Ú×=Sðo*õ¾Ú¥~ãÌÖÝ·ß]I:½ú¸©?r#Uq
@@ -0,0 +1,2 @@+xKN1CYçuP¾D¡Y±CTjMK¤3+ÕÜ¥m=Ûuô¾Ø^d2C©5ç®`,uI6¹Ô4¶jÌV=U*èÔ&)Xè+fߨú-5£sÜ6cV14E§ÜÇÜùnûìtÀEv¡c?;ÿòׯç[ýsÁ.-¼j¯µZîº)üï5¹'7XëÀ?2 &Ë9¥cúÎ6R
binary file changed (absent → 2376 bytes)
binary file changed (absent → 190 bytes)
binary file changed (absent → 93 bytes)
binary file changed (absent → 226 bytes)
@@ -0,0 +1,2 @@+x%ÎÍj1à÷)tË%ñþ@/¹JôìUׯ²elmHÞ¾¦sf>Ëba>?{S(UäÔ£Â[$æ8Ì` ´îü+UÔð¤3`^E"p73_R¡I"°èâVeÏëù¨^µ\Ç1JMèd%cY¶VD4.Ó<=îÒôÍtñág×ÄÇvçÐSa½áÖ!ÿÿ}üC6¾uÃÄ Hz
@@ -0,0 +1,3 @@+xQ=KÄ@µä?¼ÒâDQ¬®l®Ý¸ËÀ~½ñÀïÜDÔæ+áì°Ë¼yóxÛ¹Øáæöú¢:'Ê¢ªð©µvrÅðCNÑÕMÆÖ?R2ßiáY%@¸Éy 'oî½×Ë£ 6Ñ\¿ù©&;=èèk6;ÎY$£ô!ÂìIäö_búaHÔ§[Ö>¡Ob,ú KñëLªÆ±eálNeËoÂv y $nËýÑûÉÿDªÆaöØb`Ëa§zÜÚñ+ûÜëÕ[ý¬ö*Z_t~¥\
@@ -0,0 +1,1 @@+xQÁJÃ@õÈ?!mL^%-"VZüM3¡ÙLØlEýwg7Zl¢Ð]7;ï½ÍJÊ`<¾¹xð8_.ç{ß%¥T"]ïd£ÖØ-·FRŵAôá{Ñ9ÃÒÁ»»SÊÛÁÅà*£©ÙÈãU£F¾àtå0ÒMß/deø àþT³ÃR©¨ QÊ%·¢Ê5vñVµ1æí̵nÈd)ÍŹ_X*dºÒÕH^pýñ4RµÆ6}»4°'a@¹é½Î¾§ú þgÐíP£ïù{ä¡ÿòî `5YìWõ²0«úzhi|/§!LyÒ¾AÈ`t,¢E/OQærìA[ê/AûzvÍ,c½cÌê£QÝú
binary file changed (absent → 568 bytes)
binary file changed (absent → 339 bytes)
@@ -0,0 +1,1 @@+xTïÚ8½ÏHüOí©·l(Tmut·º. XÄUûÑ$±.±#Ç!¥Ûþï; ¬NÚût çÍ7cïµÇàÝÛ¿~{¼~¹¿îüé]» ©ÿyÓûåõÏv«Ýºþ?î¡Â"ápÏX0!ݺ_Xé'ëÆÄ¼ÄBèIt¦îëo&CÍK/Hº.xcØ^$Â(@ù·kriXâü+¥Ï;È93áÎ÷çJÚX_R8K3âVT#¢5VÒhx%YèÍRÂgF+3yUÁL»ãçpc´8ÄqÃס-ýi½ÛXäÈ´:h>#Í9ri>ÂIHÍC-ö á$Li-2ä¤$×i9ØaÊ%`Uì áÏ(·]Écb_Ùøe±©Y`¢P².ȯqä:·¾iÔ=(íèt±ä5»KOHkb½çE¸ÔBHWD¬2*+&T*´I=Gó¨HzÁ×ÙöËýnù¯þzí/·h7 yùWX.¨`X3Is¤"±¸[¿Pÿi6m¨LfÛåÝfÉý>Vþz;ïæþ«Ýzu¿¹ó IE8ÿÚVª4GÈ Iþ¤üjrN1;rjvÀiÜB04JÄÏ»Ü,Qòà%:¡"³Rrbzúý²,½,<¥};Íyÿ£½ê`Ï*Jê5UÖndt°Ò<)BXuö³èTÖîçN»,ëèAzØÅ-¢BîþPµ[tÑó7×` Qn#!yø¡ñÜ µ¥°æ°1ÖüNÖOúµ[Òæý¹Dìèu!Ï+MÛ±õ 3º`0@¬¯¶*óêâí¢ªÅòX±¶ÒV§±+"úÃ7PïIA»Þ<Ý?BÜÕÒ,6AëüoÿäZQ'©T°Nut^u%§ëA57 HZ©¨ù¶ë·®%±èB^n@µ³ÂlKªûÅF¥tm4ºðâêFºi·~Ü
binary file changed (absent → 871 bytes)
@@ -0,0 +1,3 @@+x¥TmoÚ0Þ×úWøÐOÄÀº µhPÛ Ø4¦}wXø%²hþ}/ ,ME¥I³Åïçî³cec¾|~·Çðj<êòÂïQ)öÖt-|ÄécsôyèLA[#RPxôp?ÿö L+5A¬ñìy³ æJ&" +IÓ{:ÌÝ9¡/;KC4 ÿfJ]!vظÏÀ:ø.â²÷QzCáL¯½uÕ/v(öÕâ=Òú2@¢.R[thômJcs/ýøªÎqJÑÄN¸NRMvÐÖ|( !k$à=X9eÑQ!!÷ãÁ`GQ1O¬h-fÐBedK ñ]¸ÿ¹nØù,ÚJÕ,gõfÁØ´uj!Ã#¬jBÆVB@¾4ìÁí)¼¯T&GècZLÖ;ëÊÉzÅYÅØ·Bª4+eÞ°!V®±Pѡۥ»ÿÄØÆ.ÁÚÉz2)I×bQñh¯,u[ÝÄ´ÿÇòÊJWI4@SÌѤþK,<Âä>ð!\_Ã-|ä÷ú@x¶½áCvÕ4MͰx¢T0´M Ç©N|UÝ:ÞJß§.·ì_¸ÖPÿáÿ£~E¬«®8ÍÅS Þ«®ü¸yú°Ðy(ç"9&Ê÷amÓjëòLzý}p2©$©`Ï~É[
binary file changed (absent → 86 bytes)
binary file changed (absent → 196 bytes)
binary file changed (absent → 94 bytes)
binary file changed (absent → 80 bytes)
binary file changed (absent → 565 bytes)
binary file changed (absent → 570 bytes)
binary file changed (absent → 192 bytes)
@@ -0,0 +1,2 @@+xÎÝm!Ea?SÅ4Å¥1ÀEF2Ë+Ï:J÷Ùòz><zoB[.2ª&ؤXb^± }¶°:è<{Ö«Úyb2ìLu1½XvÎd©ëõ¤JÍ\BQ|ÈcLº³È?to³óF7iÂ[;:~ñúæñüÌ£ªuÑ_WéC;ÕYÏMÁ¿ÕÇ Zß1YÚtìêäûO
binary file changed (absent → 47 bytes)
binary file changed (absent → 47 bytes)
binary file changed (absent → 85 bytes)
binary file changed (absent → 225 bytes)
binary file changed (absent → 1241 bytes)
binary file changed (absent → 225 bytes)
binary file changed (absent → 172 bytes)
binary file changed (absent → 191 bytes)
binary file changed (absent → 641 bytes)
binary file changed (absent → 2397 bytes)
binary file changed (absent → 2408 bytes)
binary file changed (absent → 347 bytes)
binary file changed (absent → 242 bytes)
binary file changed (absent → 94 bytes)
binary file changed (absent → 80 bytes)
binary file changed (absent → 226 bytes)
binary file changed (absent → 94 bytes)
@@ -0,0 +1,4 @@+xËmÃ0DsfÛ ~%+04àc+X.1SètÁ%ä8sxózkUÀÎæM3h4rÈì¨h-é¦`û ôìuFS2Zm8xL®8,1.v.8qtìSfËÉg¸ Xá.·>à"7þk W¸H\ëÞøØïgêís>NÖE'íµVG{h+ÿ >·á3aÂ;H%ÚÇëÉô_OÚWõ^OY
binary file changed (absent → 878 bytes)
binary file changed (absent → 1619 bytes)
binary file changed (absent → 2400 bytes)
binary file changed (absent → 226 bytes)
binary file changed (absent → 196 bytes)
binary file changed (absent → 86 bytes)
binary file changed (absent → 48 bytes)
binary file changed (absent → 557 bytes)
binary file changed (absent → 45 bytes)
binary file changed (absent → 94 bytes)
binary file changed (absent → 243 bytes)
binary file changed (absent → 86 bytes)
binary file changed (absent → 86 bytes)
binary file changed (absent → 94 bytes)
binary file changed (absent → 568 bytes)
binary file changed (absent → 226 bytes)
binary file changed (absent → 226 bytes)
binary file changed (absent → 168 bytes)
binary file changed (absent → 47 bytes)
binary file changed (absent → 195 bytes)
binary file changed (absent → 15068 bytes)
@@ -0,0 +1,2 @@+# pack-refs with: peeled +df7defd6c9e46afca38576cb5ebd89d20bad3b3e refs/remotes/origin/master
@@ -0,0 +1,1 @@+850fdfb3bae5331da0143bc338c9c2fba14c3e60
@@ -0,0 +1,1 @@+ref: refs/remotes/origin/master
@@ -0,0 +1,1 @@+850fdfb3bae5331da0143bc338c9c2fba14c3e60
@@ -0,0 +1,13 @@+----------------------------------------------------------------------------- +-- | +-- Module : Control.Monad.Imperative +-- Maintainer : Matthew Mirman <mmirman@andrew.cmu.edu> +-- Stability : experimental +-- Portability : portable +-- A front end for the ImperativeMonad +-- +----------------------------------------------------------------------------- +module Control.Monad.Imperative (module X) where + +import Control.Monad.Imperative.ImperativeMonad as X hiding (modifyOp, liftOp2) +import Control.Monad.Imperative.ImperativeOperators as X
@@ -0,0 +1,231 @@+{-# LANGUAGE + GADTs, + EmptyDataDecls, + GeneralizedNewtypeDeriving, + MultiParamTypeClasses, + FunctionalDependencies, + FlexibleInstances, + UndecidableInstances + #-} + +----------------------------------------------------------------------------- +-- | +-- Module : Control.Monad.Imperative.ImperativeMonad +-- Maintainer : Matthew Mirman <mmirman@andrew.cmu.edu> +-- Stability : experimental +-- Portability : GADTs, EmptyDataDecls, +-- GeneralizedNewtypeDeriving, MultiParamTypeClasses, +-- FunctionalDependencies, FlexibleInstances, +-- UndecidableInstances +-- A module which defines the monad for ImperativeHaskell, +-- and some control operator to interact with 'MIO' +-- +----------------------------------------------------------------------------- +module Control.Monad.Imperative.ImperativeMonad + ( modifyOp + , if' + , for' + , while' + , break' + , continue' + , return' + , returnV + , returnF + , function + , new + , auto + , runImperative + , liftOp + , liftOp2 + , liftOp3 + , liftOp4 + , liftOp5 + , V(Lit) + , (=:) + , (&) + ) where + +import Control.Monad.Cont +import Control.Monad.Reader +import Data.IORef + +newtype MIO r a = MIO { getMIO :: ReaderT (Control r) (ContT r IO) a } + deriving (Monad, MonadCont) + +data Var +data Val +data Comp + +data Control r = InFunction (r -> ContT r IO ()) + | InLoop { controlBreak::MIO r () + , controlContinue::MIO r () + , controlReturn:: r -> MIO r () + } + +-- | @'returnF' value@ acts like the imperative return, where +-- if called, it will exit the current function and place the +-- returned value into the current continuation. Note, this +-- doesn't work inside of loops. Inside of loops, we need +-- 'returnV' +returnF :: V a b b -> MIO b b +returnF v = MIO $ do + v' <- getMIO $ val v + a <- ask + case a of + InLoop _ _ ret -> getMIO $ ret v' + InFunction ret -> lift $ ret v' + return v' + +-- | @'returnV' value@ acts like the imperative return, where +-- if called, it will exit the current function and place the +-- returned value into the current continuation. Note, this +-- doesn't work as a last function call. +returnV :: V a b b -> MIO b () +returnV a = returnF a >> return () + +class Returnable b r where + -- | @'return''@ can act as returnF or returnV depending on use + -- if it does not work, it is likely that type inference + -- could not figure out a sensible alternative. + return' :: V a b b -> MIO b r + +instance Returnable b () where + return' a = returnV a + +instance Returnable b b where + return' a = returnF a + + +runImperative :: MIO a a -> IO a +runImperative foo = do + a <- runContT (callCC $ \ret -> runReaderT (getMIO foo) $ InFunction ret) return + return a + +-- | @'function' foo@ takes an ImperativeMonad action and removes it from it's +-- specific function context, specifically making it applicable +-- in the body of other functions. +function :: MIO a a -> MIO b a +function = MIO . liftIO . runImperative + +-- | @'break'@ exists the current loop. +break' :: MIO a () +break' = do + a <- MIO $ ask + case a of + InLoop br _ _ -> br + _ -> return () + +-- | @'continue'@ continues the current loop, passing over +-- any control flow that is defined. +continue' :: MIO a () +continue' = do + a <- MIO $ ask + case a of + InLoop _ con _ -> con + _ -> return () + +data V b r a where + R :: IORef a -> V Var r a + Lit :: a -> V Val r a + C :: MIO r (V b r a) -> V Comp r a + + +val :: V b r a -> MIO r a +val v = case v of + R r -> MIO $ liftIO $ readIORef r + Lit v -> return v + C m -> val =<< m + +-- | @('&')a@ gets a reference/pointer to the variable specified +(&) :: V Var r a -> V Var s a +(&) (R a) = R a + +-- | @auto@ should just be used where the +-- type can be automatically infered and we don't need an initial value +auto = undefined + +-- | @new@ constructs a new reference object with the value specified +new :: a -> MIO r (V Var r a) +new a = do + r <- MIO $ liftIO $ newIORef a + return $ R r + +infixr 0 =: + + +class Assignable val where + -- | @var '=:' value@ simply rewrites whatever + -- is in @var@ with whatever @value@ is. + (=:) :: V Var r a -> val r a -> MIO r () + +instance Assignable (V b) where + (=:) (R ar) br = MIO $ do + b <- getMIO $ val br + liftIO $ writeIORef ar b + +instance Assignable MIO where + (=:) a br = do + b <- br + a =: Lit b + +-- | @'for'(init, check, incr)@ acts like the usual imperative for loop +for' :: (MIO r irr1, V b r Bool, MIO r irr2) -> MIO r () -> MIO r () +for' (init, check, incr) body = init >> for_r + where for_r = do + do_comp <- val check + when do_comp $ callCC $ \break_foo -> do + callCC $ \continue_foo -> MIO $ do + flip withReaderT (getMIO body) $ \inbod -> + InLoop (break_foo ()) (continue_foo ()) (controlReturn inbod) + incr + for_r + +-- | @'while'(check)@ acts like the usual imperative while +while' :: V b r Bool -> MIO r () -> MIO r () +while' check = for'(return (), check, return () ) + +-- | @'if'(check) m@ only executes m if the check is true. +-- it is specifically value in it's argument. +if' :: V b r Bool -> MIO r () -> MIO r () +if' b m = do + v <- val b + when v m + +-- | @'modifyOp' f@ makes a modify operator out of a binary +-- haskell function +modifyOp :: (a->b->a) -> V Var r a -> V k r b -> MIO r () +modifyOp op (R ar) br = MIO $ do + b <- getMIO $ val br + liftIO $ modifyIORef ar (\v -> op v b) + +-- | @'liftOp' f@ turns a pure function into one which +-- gets the values out of it's arguments +liftOp foo a = C $ do + a' <- val a + return $ Lit $ foo a' + +liftOp2 foo a1 a2 = C $ do + a1' <- val a1 + a2' <- val a2 + return $ Lit $ foo a1' a2' + +liftOp3 foo v1 v2 v3 = C $ do + v1' <- val v1 + v2' <- val v2 + v3' <- val v3 + return $ Lit $ foo v1' v2' v3' + +liftOp4 foo v1 v2 v3 v4 = C $ do + v1' <- val v1 + v2' <- val v2 + v3' <- val v3 + v4' <- val v4 + return $ Lit $ foo v1' v2' v3' v4' + +liftOp5 foo v1 v2 v3 v4 v5 = C $ do + v1' <- val v1 + v2' <- val v2 + v3' <- val v3 + v4' <- val v4 + v5' <- val v5 + return $ Lit $ foo v1' v2' v3' v5' v4'
@@ -0,0 +1,26 @@+{-# LANGUAGE + NoMonomorphismRestriction + #-} +----------------------------------------------------------------------------- +-- | +-- Module : Control.Monad.Imperative.ImperativeOperators +-- Maintainer : Matthew Mirman <mmirman@andrew.cmu.edu> +-- Stability : experimental +-- Portability : NoMonomorphismRestriction +-- Some predefined operators for the imperative monad. +-- +----------------------------------------------------------------------------- +module Control.Monad.Imperative.ImperativeOperators where + +import Control.Monad.Imperative.ImperativeMonad (modifyOp, liftOp2) + + +(+=:) = modifyOp (+) +(*=:) = modifyOp (*) +(-=:) = modifyOp (-) +(%=:) = modifyOp (mod) + +(<.) = liftOp2 (<) +(>.) = liftOp2 (>) +(+.) = liftOp2 (+) +(*.) = liftOp2 (*)
@@ -0,0 +1,40 @@+Name: ImperativeHaskell+Version: 0.2.0.0+Description: A monad that uses GADTs and continuations+ to replicate what it is like to program+ in an imperative language like C or Java+ with "return", "for", "break", "continue", + and mutable references.+Synopsis: A library for writing Imperative style haskell.++Homepage: https://github.com/mmirman/ImperativeHaskell++License: GPL-3++License-file: LICENSE++Author: Matthew Mirman++Maintainer: Matthew Mirman <mmirman@andrew.cmu.edu>++Category: Control++Build-type: Simple++Cabal-version: >=1.6++Source-repository head+ Type: git+ Location: git://github.com/mmirman/ImperativeHaskell.git++Library+ + Build-depends: base >= 4.0 && < 5.0, + mtl > 2.0 && < 3.0+ + Exposed-modules: Control.Monad.Imperative,+ Control.Monad.Imperative.ImperativeMonad,+ Control.Monad.Imperative.ImperativeOperators+ + Extensions: GADTs, EmptyDataDecls, NoMonomorphismRestriction, GeneralizedNewtypeDeriving, MultiParamTypeClasses, FunctionalDependencies, FlexibleInstances, UndecidableInstances+
@@ -0,0 +1,320 @@+ GNU GENERAL PUBLIC LICENSE+ Version 3, 29 June 2007++ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>+ Everyone is permitted to copy and distribute verbatim copies+ of this license document, but changing it is not allowed.++ Preamble++ The GNU General Public License is a free, copyleft license for+software and other kinds of works.++ The licenses for most software and other practical works are designed+to take away your freedom to share and change the works. By contrast,+the GNU General Public License is intended to guarantee your freedom to+share and change all versions of a program--to make sure it remains free+software for all its users. We, the Free Software Foundation, use the+GNU General Public License for most of our software; it applies also to+any other work released this way by its authors. You can apply it to+your programs, too.++ When we speak of free software, we are referring to freedom, not+price. Our General Public Licenses are designed to make sure that you+have the freedom to distribute copies of free software (and charge for+them if you wish), that you receive source code or can get it if you+want it, that you can change the software or use pieces of it in new+free programs, and that you know you can do these things.++ To protect your rights, we need to prevent others from denying you+these rights or asking you to surrender the rights. Therefore, you have+certain responsibilities if you distribute copies of the software, or if+you modify it: responsibilities to respect the freedom of others.++ For example, if you distribute copies of such a program, whether+gratis or for a fee, you must pass on to the recipients the same+freedoms that you received. You must make sure that they, too, receive+or can get the source code. And you must show them these terms so they+know their rights.++ Developers that use the GNU GPL protect your rights with two steps:+(1) assert copyright on the software, and (2) offer you this License+giving you legal permission to copy, distribute and/or modify it.++ For the developers' and authors' protection, the GPL clearly explains+that there is no warranty for this free software. For both users' and+authors' sake, the GPL requires that modified versions be marked as+changed, so that their problems will not be attributed erroneously to+authors of previous versions.++ Some devices are designed to deny users access to install or run+modified versions of the software inside them, although the manufacturer+can do so. This is fundamentally incompatible with the aim of+protecting users' freedom to change the software. The systematic+pattern of such abuse occurs in the area of products for individuals to+use, which is precisely where it is most unacceptable. Therefore, we+have designed this version of the GPL to prohibit the practice for those+products. If such problems arise substantially in other domains, we+stand ready to extend this provision to those domains in future versions+of the GPL, as needed to protect the freedom of users.++ Finally, every program is threatened constantly by software patents.+States should not allow patents to restrict development and use of+software on general-purpose computers, but in those that do, we wish to+avoid the special danger that patents applied to a free program could+make it effectively proprietary. To prevent this, the GPL assures that+patents cannot be used to render the program non-free.++ The precise terms and conditions for copying, distribution and+modification follow.++ TERMS AND CONDITIONS++ 0. Definitions.++ "This License" refers to version 3 of the GNU General Public License.++ "Copyright" also means copyright-like laws that apply to other kinds of+works, such as semiconductor masks.++ "The Program" refers to any copyrightable work licensed under this+License. Each licensee is addressed as "you". "Licensees" and+"recipients" may be individuals or organizations.++ To "modify" a work means to copy from or adapt all or part of the work+in a fashion requiring copyright permission, other than the making of an+exact copy. The resulting work is called a "modified version" of the+earlier work or a work "based on" the earlier work.++ A "covered work" means either the unmodified Program or a work based+on the Program.++ To "propagate" a work means to do anything with it that, without+permission, would make you directly or secondarily liable for+infringement under applicable copyright law, except executing it on a+computer or modifying a private copy. Propagation includes copying,+distribution (with or without modification), making available to the+public, and in some countries other activities as well.++ To "convey" a work means any kind of propagation that enables other+parties to make or receive copies. Mere interaction with a user through+a computer network, with no transfer of a copy, is not conveying.++ An interactive user interface displays "Appropriate Legal Notices"+to the extent that it includes a convenient and prominently visible+feature that (1) displays an appropriate copyright notice, and (2)+tells the user that there is no warranty for the work (except to the+extent that warranties are provided), that licensees may convey the+work under this License, and how to view a copy of this License. If+the interface presents a list of user commands or options, such as a+menu, a prominent item in the list meets this criterion.++ 1. Source Code.++ The "source code" for a work means the preferred form of the work+for making modifications to it. "Object code" means any non-source+form of a work.++ A "Standard Interface" means an interface that either is an official+standard defined by a recognized standards body, or, in the case of+interfaces specified for a particular programming language, one that+is widely used among developers working in that language.++ The "System Libraries" of an executable work include anything, other+than the work as a whole, that (a) is included in the normal form of+packaging a Major Component, but which is not part of that Major+Component, and (b) serves only to enable use of the work with that+Major "Major Component", in this context, means a major essential component+(kernel, window system, and so on) of the specific operating system+(if any) on which the executable work r, it does not include the work's+System Libraries, or general-purpose tools or generally available free+programs which are used unmodified in performing those activities but+which are not part of the work. For eose+subprograms and other parts of the work.++ The Corresponding Source need not include anything that users+can regenerate automatically from other parts of the work.++ 2. Basic Permissions.++ All rights gran unmodified Program. The output from running a+covered work is covered by this++ You may make, run and propagate covered works that you do not+convey, without conditions so long as your license otherwise remainyou, or proively on your behalf, under your direction+and control, on terms that prohibit them from making any copies of+your copyrighted material outside their relationship with you.++ Conveying under any otherg obligations under article+11 of the WIPO copyright treaty adopted on 20 December 1996, or+similar laws prohibiting or restricting circumvention of such+measures.++ When you convey a covered work, you waive any k's+users, your or third parties' legal rights to forbidsly and+appropriately publish on each copy an appropriate copyright notice;+keep intact all notices stating that this License and any+non-permissive terms amay convey a work based on the Program, or the modifications to+produce it from the Program, in the form of source code under the+terms of section 4, provided that you also meet all of these conditions:++ a) T+ "keep intact all notices".++ c) You must license the entire work, as a whole, under this+ License to anyone who comes into possession of a copy. This+ License will therefore apply, along with any ae work has interactive user interfaces, each must display+ Appropriate Legal Notices; however, if the Program has interactive+ interfaces that do not display Apered work with other separate and independent+regate" if the compilation and its resulting copyright are not+used to limit the access or legal rights of the c the other+parts of the aggregate.++ 6. Conveying Non-Source Forms.++ You may convey a covered woricensware interchange.++ b) Convey the object code in, or embodied in, a physical product+ (including a physical distribution medium), accompanied by a+ written offer, valid for at least three years and ly used for software interchange, for a price no+ more than your reasonable cost of physically performing this+ conveying of source, or (2) access to copy the+ Correes of the object code with a copy of tection 6b.++ d) Convey the object code by offering access from a designated+ place (gratis or for a charge),quire recipients to copy the+ Corresponding Source along with the object code. If the place toequival available for as long as needed to satisfy these requirements.++ e) Convey the object code using peer-to-peer transmission, provided+ you inform other peers where the object code and Corresponding+her (1) a "consumer product", which means any+tangible personal property which is normally used for personal, family,+or household purposes, or (2) anything designed or sold for incorporation+into a dwelling. Inway in which the particular user+ly significant mode of use of the product.++ "Installation Information" for a User Product means any methods,+procedures, authorization keys, or other information required to insbject code work under this section in, or with, or+specifically for use in, a User Product, and the conveying occurs as+part of a transaction in which the right of possession and use of the+User Product is transf ability to install+modified object code on the User Product (for example, the work has+been installed in ROM).++ The requirement to provide Installation Information does not include a+requirement to continue totwork or violates the rules and+protocols for communica available to the public in+source code form), and must require no special password or key for+unpacking, reading or copying.++ 7. Additional Terms.++ "Addpart of the Program, that part may be used separately+under those permissions, but the entire Program remains governed by+this License without regard to the additional permissions.++ When you convey a copy of a work,+for which you have or can give appropriate copyright permission.++ Notwithstanding any other provision of this License, for material you+add to a covered work, you may (if authorized by the copyright f thaterial or in the Apt from the original version; or++ d) Limiting the use for publicity purposes of names of licensors or+ authors of the material; or++ e) Declining to grant rights under trademark law fsumptions directly impose on+ those licensors and authors.++ All other non-permissive additional terms are considered "further+restrictions" within the meaning of section 10. If the Program as you+received itmaterial governed by the terms+of that license document, provided that the further restriction does+not survive such relicensing or conveying.++ If you add terms to a covered work in accord with this section, yo+the above requirements apply either way.++ 8. Termination.++ You may not propagate or rights under+this License (including any patent licenses granted under the third+paragraph of section 11).++ However, if y particular copyright holder is+reinstated permanently if the copyright holder notifies you of the+violation by some reasonable means, this is the first time you have+received notice of violation of this License en terminated and not permanently+reinstated, you do not qualify to receive new licenses for the same+material under section 10.++ 9. Acceptance Not Required for Having Copies.++ You are not required to accepy agate or+modify any covered work. These actions infringe copyright if you do+not accept this License. Therefore, by ecipients.++ Each time you convey a covered work, the recipient automatically+receives a licey transaction, each party to that+transaction who receives a copy of the work also receives whatever+licenses to the work the party's predecessor in interest had or could+give under the previous paragraph, plus a ot impose a license fee, royalty, or other charge for exercise of+rights granted under this License, and you may not initiate litigation+(including a cross-claim or counterclaim in a lawsuit) allling, offering fd the contributor's "contributor version".++ A contributor's "essential patent claims" are all patent claims+owned oLicense, of making, using, or selling its contributor version,+but do not include claims that wimport and otherwise run, modify and+propagate the contents of its contributor version.++ In the following three paragraphs, a "patent license" is any express+agreement or commitment, however denominated, not toing on a patent license,+and the Corresponding Source of the work is not available for anyone+to copy, free of charge and under the terms of this1) cause the Corresponding Source to be so+available, or (2) arrangse to downstream recipients. "Knowingly relying" means you have+actual kble patents in that+country that you have reason to believe are valid.++ If, pursuant to or in connection with a single transaction or+arratent license is "discriminatory" if it does not include within+the scope of its coverage, prohibits the exercise of, or is+conditioned on the non-exercise of one or more of the rights that are+specifically grantrty grants, to any of the+parties who would receive the covered work from you, a discriminatory+patent license (a) in connection with copies of the c specific products or compilations that+contain the covered workse orions of this License, they do not+excuse you from the conditions of this License. If you cannot convey a+covered work so as to satisfy simultaneously your obligations under this+License and any other pertinom conveying the Program.++ 13. Use with the GNU Affero General Public License.++ Notwithstanding any other provision of this License, you have+permission to link or combine any covered work with a work licensening interaction through a network will apply to the+combination as such.++ 14. Revised Versions of this License.++ The Free Software Foundation may pubns will+be similar in spirit to the present version, but m License "or any later version" ap the+GNU General Public License, you may choose any version ever published+by the Free Software Foundation.++ If the Program specifies that a proxy can decide which future+versis a result of your choosing to follow a+later version.++ 15. Disclaimer of Warranty.++ THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY+APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING TOGRAM+IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF+ALL NECESSARY SERVICING, REPAIR OR CORRECTION.++ 16. Limitation of Liability.++ IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGITED TO LOSS OF+DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD+PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),+EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN A7. ute waiver of all civil liability in connection with the+Program, unless a warranty or assumption of liability accompanies a+copy of the Program in return for a Your New Programs
@@ -0,0 +1,73 @@+{-# LANGUAGE + GADTs + #-} + +----------------------------------------------------------------------------- +-- | +-- Module : Main +-- Author : Matthew Mirman ( mmirman@andrew.cmu.edu ) +-- Stability : experimental +-- Portability : portable +-- Description : An example module for Control.Monad.Imperative +-- +-- Copyright (C) 2012 Matthew Mirman +-- +-- This program is free software: you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation, either version 3 of the License, or +-- (at your option) any later version. +-- +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with this program. If not, see <http://www.gnu.org/licenses/> + +module Main where + +import Control.Monad.Imperative + +swap(r1, r2) = function $ do +{ + z <- new auto; + z =: r1; + r1 =: r2; + r2 =: z; +}; + +imperativeId(r1) = function $ do +{ + return' r1; +}; + +factorial = function $ do +{ + a <- new 0; + n <- new 1; + for' ( a =: Lit 1 , a <. Lit 11 , a +=: Lit 1 ) $ do + { + n *=: a; + if' ( a <. Lit 7) + continue'; + + + + if' ( a >. Lit 5) + break'; + + return' a; + }; + + a =: imperativeId(a); + + swap( (&)n , (&)a); + + return' n; +}; + + +main = do + t <- runImperative factorial + putStrLn $ "Some Factorial: "++show (t :: Int)
@@ -0,0 +1,6 @@+Just proof that Haskell' can be truly imperative, and even look like C.++For some background, look in http://kormacode.blogspot.com/2011/11/c-style-haskell_10.html++For an example usage, look in Main.hs.+
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
@@ -9,8 +9,7 @@ -- Stability : experimental -- Portability : portable -- Description : An example module for Control.Monad.Imperative --- --- License : GNUv3 +-- License : GNU-3 -- -- Copyright (C) 2012 Matthew Mirman -- @@ -29,37 +28,47 @@ module Main where -import Prelude hiding (break) import Control.Monad.Imperative swap(r1, r2) = function $ do { - z <- auto undefined; + z <- new auto; z =: r1; r1 =: r2; r2 =: z; }; +imperativeId(r1) = function $ do +{ + return' r1; +}; + factorial = function $ do { - a <- auto 0; - n <- auto 1; - for ( a =: prim 1 , a <. prim 11 , a +=: prim 1 ) $ do + a <- new 0; + n <- new 1; + for' ( a =: Lit 1 , a <. Lit 11 , a +=: Lit 1 ) $ do { n *=: a; - if' ( a <. prim 7) - continue; + if' ( a <. Lit 7) + continue'; + - if' ( a >. prim 5) - break; - }; + + if' ( a >. Lit 5) + break'; + return' a; + }; + + a =: imperativeId(a); + swap( (&)n , (&)a); - - returnF n; + + return' n; }; main = do t <- runImperative factorial - putStrLn $ "Some Factorial: "++show t + putStrLn $ "Some Factorial: "++show (t :: Int)
@@ -1,1 +1,6 @@ Just proof that Haskell' can be truly imperative, and even look like C.++For some background, look in http://kormacode.blogspot.com/2011/11/c-style-haskell_10.html++For an example usage, look in Main.hs.+