Created
January 8, 2017 00:14
-
-
Save isovector/cd4660c784689077b0750664404e6be2 to your computer and use it in GitHub Desktop.
pascal dot haskell
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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