int ShowMainMenu()
double AddFunds()
- Ask user for how many funds to add
double WithdrawFunds()
- Ask user for how many funds to withdraw
void InsufficientFundsToWithdraw()
-- save as HaskellCheatsheet.hs | |
module HaskellCheatsheet where | |
-- On Windows, I sometimes have to remove the module line above | |
-- in order to get GHC to compile the file as an executable instead | |
-- of a library. | |
-- Single line comment | |
{- |
from timeit import timeit | |
a = list(range(6)) | |
num = 1_000_000 | |
print("toons's: ", timeit(""" | |
i = iter(islice(iter(a), 0, len(a), 2)) | |
j = iter(islice(iter(a), 1, len(a), 2)) | |
try: |
using System; | |
using System.Threading; | |
// S is the type stored for successful computations, E for errors | |
public struct Result<S, E> | |
{ | |
private bool isSuccessful; | |
private S successValue; | |
private E errorValue; |
def Zero(zero_val): | |
return lambda rec_func: zero_val | |
def Succ(nat): | |
return lambda zero_val: lambda rec_func: rec_func(nat) | |
def add(a): | |
return (lambda b: |
from typing import List | |
from pyrsistent import pvector | |
from pyrsistent.typing import PVector | |
def benchmark_jump(n: int): | |
string = 'xx.' * n | |
for i in range(0, n, 3): | |
string = jump(string, i, 1) |
# Forgets results in between calls | |
# Also, it is nowhere close to as efficient as the Haskell version | |
# i.e. I think this is exponential in time | |
def fibs_gen(): | |
yield 0 | |
yield 1 | |
fib = fibs_gen() | |
fib_tail = fibs_gen() |
hailstone :: [[Int]] | |
hailstone = [] : [1] : map (\n -> let n' = collatz n in n : (hailstone !! n')) [2..] | |
collatz n = if even then half else 3 * n + 1 | |
where | |
(half, r) = n `quotRem` 2 | |
even = r == 0 | |
{- GHCI output, _ means that part hasn't been evaluated yet | |
Prelude> hailstone !! 3 |
def fib(n): | |
a, b = 0, 1 | |
for _ in range(n): | |
a, b = b, a + b | |
return a | |
# fib n = go 0 1 n | |
# where go a _ 0 = a | |
# go a b n = go b (a + b) (n - 1) |