Skip to content

Instantly share code, notes, and snippets.

@isovector
Created January 8, 2017 00:14
Show Gist options
  • Select an option

  • Save isovector/cd4660c784689077b0750664404e6be2 to your computer and use it in GitHub Desktop.

Select an option

Save isovector/cd4660c784689077b0750664404e6be2 to your computer and use it in GitHub Desktop.
pascal dot haskell
import Data.Semigroup
import Control.Comonad
import Control.Comonad.Store
pascalLine :: Store (Int, Int) Int -> Int
pascalLine w | x <= 0 = 1
| y <= 0 = 1
| otherwise = peek (x-1, y) w + peek (x, y-1) w
where
(x, y) = pos w
instance Semigroup Int where
(<>) = (+)
pascal :: Store (Int, Int) Int
pascal = cfix pascalLine
test :: Int
test = peek (0,0) pascal -- infinitely loops
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment