This file contains 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
-- Run on GHC 7.6.1 | |
{-# LANGUAGE DataKinds #-} | |
{-# LANGUAGE PolyKinds #-} | |
{-# LANGUAGE TypeFamilies #-} | |
{-# LANGUAGE TypeOperators #-} | |
{-# LANGUAGE GADTs #-} | |
{-# LANGUAGE RankNTypes #-} | |
{-# LANGUAGE FlexibleContexts #-} |
This file contains 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
-- $ ghci | |
-- GHCi, version 7.6.1: http://www.haskell.org/ghc/ :? for help | |
ghci> import GHC.TypeLits | |
ghci> :set -XDataKinds | |
ghci> :set -XPolyKinds | |
ghci> :set -XGADTs | |
ghci> data EqRefl a b where { Refl :: EqRefl a a } | |
ghci> :t Refl :: EqRefl 1 1 | |
Refl :: EqRefl 1 1 :: EqRefl Nat 1 1 |
This file contains 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 FlexibleContexts #-} | |
import Data.Conduit | |
import qualified Data.Conduit.List as CL | |
import Network.HTTP.Conduit | |
import Control.Concurrent.Async (mapConcurrently) | |
import Control.Concurrent.MVar | |
import Control.Monad.IO.Class (liftIO) | |
import Control.Monad.Trans.Control (MonadBaseControl) |
This file contains 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
-- Run on GHC 7.4.2 | |
{-# LANGUAGE FlexibleInstances #-} | |
{-# LANGUAGE OverlappingInstances #-} | |
{-# LANGUAGE UndecidableInstances #-} | |
{-# LANGUAGE DataKinds #-} | |
{-# LANGUAGE PolyKinds #-} | |
{-# LANGUAGE TypeFamilies #-} | |
{-# LANGUAGE TypeOperators #-} | |
{-# LANGUAGE ScopedTypeVariables #-} |
This file contains 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 #-} | |
data Nil | |
data Cons | |
data StrongList x tag where | |
Nil :: StrongList a Nil | |
Cons :: a -> StrongList a b -> StrongList a Cons | |
safeHead :: StrongList x Cons -> x |
This file contains 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 #-} | |
data MyString | |
data MyInt | |
data MyNil | |
data MyData tag where | |
MyString :: String -> MyData MyString | |
MyInt :: Int -> MyData MyInt | |
MyNil :: MyData MyNil |
This file contains 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.Arrow (first) | |
import Control.Monad.List | |
import Control.Monad.Writer | |
liftList :: (Monad m) => [a] -> ListT m a | |
liftList = ListT . return | |
splites :: Int -> [(Int, Int)] | |
splites n = [ (x, n - x) | x <- [1..n-1] ] |
This file contains 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
splites :: Int -> [(Int, Int)] | |
splites n = [ (x, n - x) | x <- [1..n-1] ] | |
count :: Int -> Int | |
count 1 = 1 | |
count n = sum $ do | |
(i, j) <- splites n | |
return $ count i * count j |
This file contains 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
;; (defproject async-test2 "0.1.0-SNAPSHOT" | |
;; :description "FIXME: write description" | |
;; :url "http://example.com/FIXME" | |
;; :license {:name "Eclipse Public License" | |
;; :url "http://www.eclipse.org/legal/epl-v10.html"} | |
;; :dependencies [[org.clojure/clojure "1.4.0"] | |
;; [http.async.client "0.4.5"]]) | |
(ns async-test2.core |
This file contains 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.Monad.State | |
splitEvery :: Int -> [a] -> [[a]] | |
splitEvery n = takeWhile (not . null) . evalState (sequence $ repeat (state (splitAt n))) | |
{- | |
ghci> splitEvery 5 [1..27] | |
[[1,2,3,4,5],[6,7,8,9,10],[11,12,13,14,15],[16,17,18,19,20],[21,22,23,24,25],[26,27]] | |
ghci> splitEvery 5 [] | |
[] |