Skip to content

Instantly share code, notes, and snippets.

{-# LANGUAGE RankNTypes, GADTs, KindSignatures, ScopedTypeVariables, DataKinds,
TypeSynonymInstances, FlexibleInstances, OverlappingInstances,
TypeOperators, StandaloneDeriving #-}
module MyData.Trie where
import Control.Arrow
import Data.Array
import Data.Bits
import Data.Char
data Container :: * -> * -> * where
-- Some other cases go here
Map :: (a -> b) -> Container b v -> Container a v
-- Think a map type, k to v
combine :: (v -> v -> v) -> Container k v -> Container k v -> Container k v
combine c (Map f ct1) (Map g ct2) = Map f $ combine c ct1 ct2
@possiblywrong
possiblywrong / fizzbuzz.hs
Created May 23, 2014 08:32
Codata FizzBuzz
import Data.Function
fizzBuzz n | n `mod` 15 == 0 = "FizzBuzz"
| n `mod` 5 == 0 = "Buzz"
| n `mod` 3 == 0 = "Fizz"
| otherwise = show n
fzb = fix (\x acc -> (fizzBuzz acc):(x (acc+1))) 1
-- take 100 fzb
@possiblywrong
possiblywrong / gist:8822528
Created February 5, 2014 12:21
Rough sketch
object TestCase {
trait MYtype[A]
case class Bob(i: Int) extends MYType[Int]
case class Wibble[A,B](t1: MYType[A], t2: MYType[B]) extends MYType[A\/B]
// MYType => ( List[(A,B)] => List[B] )
// So we define myfun for each member of the MYType ADT
object myfun extends Poly1 {
implicit def caseOne = at[Bob]( i => { ... somefn } )
implicit def caseTwo[A,B] = at[Wibble[A,B]]( i => { { xs => myfun(as) ++ myfun(bs) } } )
@possiblywrong
possiblywrong / gist:8821766
Created February 5, 2014 11:32
Discriminated sort
ackage discsort
import scalaz._, Scalaz._
import shapeless._
// Attempt at implementing generic discrimiated sort,
// based on the following paper;
// www.diku.dk/hjemmesider/ansatte/henglein/papers/henglein2011a.pdf
trait SOrder[A]
case class Nat0(i: Int) extends SOrder[Int]
@possiblywrong
possiblywrong / gist:8820864
Created February 5, 2014 10:32
Shapeless poly binding & inference
object TestCase {
// Given input of type X return a function of
// type List[(A,B)] => List[B] forall B
// Types X & A are related
object filt extends Poly1 {
implicit def caseOne = at[Int]( i => {
object partialbind extends somefn(i);
partialbind
} )
// ...may have other cases
@possiblywrong
possiblywrong / dabblet.css
Created February 3, 2013 05:50
Nested div masked off by circular container div (SO)
/**
* Nested div masked off by circular container div (SO)
* http://stackoverflow.com/q/12964400/1397351
*/
#nav{
width: 100%;
height: 2em;
}
.aaa{