Skip to content

Instantly share code, notes, and snippets.

@patrickaldis
patrickaldis / recursion.md
Last active August 22, 2022 09:56
`gcd` recursion

gcd Recursion

While testing gcd function I ended up needing to know a termination bound for gcd m n, so had to investigate how many steps the recursion took. The case I tested was for gcd 7 5 - it had enough steps. The defintion for gcd follows the euclidean algorithm, which reduces gcd a b to gcd b c
for a smaller c. At each stage, this reduction is simply c = a rem b

gcd 7 5

Algorithm terminates in 4 steps:

@patrickaldis
patrickaldis / monadhelp.md
Created August 3, 2022 10:53
Monad Help

Currently Reading - http://blog.sigfpe.com/2006/08/you-could-have-invented-monads-and.html

I've worked through the first 6 examples where you create bind and unit functions for each "would-be" monad. But I'm having trouble understanding the "Random Numbers" example. (Just after excercise 6)

Slightly confused by how the types of the outputs of f, g are going to agree - Both output b and accept a.

My main problem is with the type signature of bind for the functions.

Keybase proof

I hereby claim:

  • I am patrickaldis on github.
  • I am patrickaldis (https://keybase.io/patrickaldis) on keybase.
  • I have a public key ASBVgPesD9hm4xrQMCmrdfBsGxIwRE2PzgiJWdLRLI5CsAo

To claim this, I am signing this object: