Skip to content

Instantly share code, notes, and snippets.

@michaelt
Created July 21, 2013 20:06
Show Gist options
  • Save michaelt/6049784 to your computer and use it in GitHub Desktop.
Save michaelt/6049784 to your computer and use it in GitHub Desktop.
-- file Hello.hscript
"Hello world"
let val = id
let assert = id
let a = 3
val a
let square x = x * x
val $ square 3
square 5
"lets make an assertion: square (-1) == square 1"
assert $ square (-1) == square 1
"no lets just quickcheck it for arbirary n, square (-n) == square n"
import Test.QuickCheck
quickCheck $ \n -> square (-n) == square n
:{
let fib 0 = 0
fib 1 = 1
fib n = fib (n-1) + fib (n-2)
:}
"lets do some arbitrary IO!"
hscript <- readFile "Hello.hscript"
"Does this file start with \"Hello world\"?"
assert $ take 13 hscript == "\"Hello world\""
"lets mutate some variables!!"
import Data.IORef
let (?) = readIORef
let (++) = flip modifyIORef (+1)
"lets let x be 1"
x <- newIORef (1 :: Integer)
"whats x?"
(x?)
"let's increment x again"
(x++)
"what's x?"
(x?)
"let's increment x again"
(x++)
"what's x?"
(x?)
"let's increment x again"
(x++)
"what's x?"
(x?)
"wait, fib 13, what was that?"
fib 13
"let's increment x again"
(x++)
(x?)
data Hi = Hi | Ho deriving (Eq,Ord,Show)
:{
let hi Ho = Hi
hi Hi = Ho
:}
assert $ Hi == hi Ho
Hi
import System.Directory
import Control.Monad ((>=>))
d <- getDirectoryContents "." >>= mapM getPermissions
let e = filter executable d
mapM_ print e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment