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
| {-# LANGUAGE TypeFamilies #-} | |
| {-# LANGUAGE FlexibleInstances #-} | |
| {-# LANGUAGE UndecidableInstances #-} | |
| {-# LANGUAGE MultiParamTypeClasses #-} | |
| module RotateArgs where | |
| data Z = Z | |
| data S n = S n | |
| class RotateArgs n a where |
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
| // for more info http://www.cs.tufts.edu/~nr/cs257/archive/john-hughes/lists.pdf | |
| type FuncList<'a> = 'a list -> 'a list | |
| // Monoid comprehension | |
| type FuncListBuilder() = | |
| member self.Combine (first : FuncList<'a>, second : FuncList<'a>) : FuncList<'a> = (first << second) | |
| member self.Zero() : FuncList<'a> = id | |
| member self.Yield (value : 'a) : FuncList<'a> = fun tail -> value :: tail | |
| member self.YieldFrom (value : FuncList<'a>) : FuncList<'a> = value | |
| member self.Delay ( f : unit -> FuncList<'a>) : FuncList<'a> = (fun tail -> f () tail) |
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
| type FuncList<'a> = 'a list -> 'a list | |
| type CPSFuncList<'a> = FuncList<'a> -> FuncList<'a> | |
| // Monoid comprehension | |
| type CPSFuncListBuilder() = | |
| member self.Combine (first : CPSFuncList<'a>, second : CPSFuncList<'a>) : CPSFuncList<'a> = | |
| (fun k -> second (fun tail -> first (fun tail' -> k tail') tail)) | |
| member self.Zero() : CPSFuncList<'a> = (fun k tail -> k tail) | |
| member self.Yield (value : 'a) : CPSFuncList<'a> = (fun k tail -> k (value :: tail)) | |
| member self.YieldFrom (value : CPSFuncList<'a>) : CPSFuncList<'a> = value |
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
| vendor/ | |
| composer.lock |
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
| fizzbuzz :: Int -> String | |
| fizzbuzz n = unlines $ map fizzbuzz' [1 .. n] | |
| where | |
| fizzbuzz' n = let p = n `mod` 3 == 0 | |
| q = n `mod` 5 == 0 | |
| in case (p, q) of | |
| (p, q) | p && q -> "FizzBuzz" | |
| | p -> "Fizz" | |
| | q -> "Buzz" | |
| | otherwise -> show n |
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
| -- playing with the adaptive library. | |
| import Control.Monad.Adaptive | |
| printMod mod = do | |
| r <- inCh $ readMod mod | |
| inM (putStrLn $ show r) | |
| main = run $ do | |
| i1 <- newMod (return (2 :: Integer)) |
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
| -- static Peano constructors and numerals | |
| data Zero | |
| data Succ n | |
| type One = Succ Zero | |
| type Two = Succ One | |
| type Three = Succ Two | |
| type Four = Succ Three |
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.Word | |
| freq = 0.3 | |
| spread = 8.0 | |
| unbase :: Integral int => int -> Word8 -> Word8 -> Word8 -> int | |
| unbase base r g b = (fi r*base+fi g)*base+fi b | |
| where fi = fromIntegral | |
| -- | Approximate a 24-bit Rgb colour with a colour in the xterm256 6x6x6 colour cube, returning its index. |
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
| {-# LANGUAGE GADTs, EmptyDataDecls, ExistentialQuantification #-} | |
| module RBTree where | |
| -- Node color | |
| data Red | |
| data Black | |
| -- Node depth |
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 Control.Applicative | |
| import Data.Functor.Constant | |
| import Data.Generics.Multiplate | |
| data ZigZag a b = ZNil | Zig a (ZigZag a b) | Zag b (ZigZag b a) | |
| data ZigZagPlate a b f = ZigZagPlate | |
| { znilab :: f (ZigZag a b) | |
| , zigab :: a -> ZigZag a b -> f (ZigZag a b) | |
| , zagab :: b -> ZigZag b a -> f (ZigZag a b) |