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
#!/usr/bin/env sh | |
browser=chromium-browser | |
package=${1-base} | |
ghc-pkg describe $package | \ | |
grep haddock-html | \ | |
awk '{ print $2 "/index.html" }' | \ | |
xargs $browser &> /dev/null |
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 OverloadedStrings #-} | |
module Main where | |
import Control.Concurrent (forkIO, ThreadId) | |
import Data.ByteString.Lazy (ByteString) | |
import Data.Text.Lazy (pack) | |
import Data.Text.Lazy.Encoding (encodeUtf8) | |
import Network.HTTP.Types (status200) | |
import Network.HTTP.Types.Header (hContentType) |
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
module Main where | |
import Data.Aeson hiding (Result) | |
import Data.Aeson.Encode.Pretty (encodePretty) | |
import Data.Attoparsec.ByteString | |
import Data.ByteString (ByteString) | |
import qualified Data.ByteString.Char8 as BS | |
import Data.ByteString.Lazy (toStrict) | |
import System.Console.ANSI |
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 GeneralizedNewtypeDeriving #-} | |
module Main where | |
import Data.Functor | |
import Control.Monad | |
import Control.Monad.State | |
import Control.Monad.Writer | |
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
-- http://hackage.haskell.org/package/base-4.6.0.1/docs/src/GHC-Base.html#map | |
map :: (a -> b) -> [a] -> [b] | |
map _ [] = [] | |
map f (x:xs) = f x : map f xs |
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
data Dog = Dog { name :: Text | |
, age :: Int | |
, likes :: Text | |
} deriving Show | |
instance ToJSON Dog where | |
toJSON = asObject [ name `as` "name" | |
, age `as` "age" | |
, likes `as` "likes" | |
] |
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
object Chap5 extends App { | |
import Stream._ | |
def ones: Stream[Int] = cons(1, ones) | |
def lin: Stream[Int] = cons(1, lin.map(_ + 1)) | |
println(ones.flatMap(_ => empty[Int])) // Stack overflow! | |
} | |
sealed trait Stream[A] { |
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 scalaz.Scalaz._ | |
/** The problem: given the following database query results, associate each parentId to | |
* a List of filenames. | |
*/ | |
case class Row(parentId: Int, file: String) | |
val queryResult = Stream(Row(123, "foo.jpg"), Row(123, "bar.jpg"), Row(234, "foo.png")) | |
/** Using foldLeft is verbose because we have to specify: | |
* - how to create an empty Map to begin with |
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
object PragmaticParens { | |
import scalaz._, Scalaz._, typelevel._ | |
private def f(c: Char): StateT[Option, Nat, Unit] = | |
StateT(nat => (c match { | |
case '(' => Some(nat.succ) | |
case ')' => nat.pred | |
case _ => Some(nat) | |
}) map (_ -> ())) |
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 scalaz._, syntax.monad._ | |
final def filterMN[A, M[_]:Monad, N[_]:Monad](as: List[A])(p: A => N[M[Boolean]]): N[M[List[A]]] = | |
as match { | |
case Nil => Monad[N].point(Monad[M].point(Nil)) | |
case h :: t => | |
for { | |
mb <- p(h) | |
mg <- filterMN(t)(p) | |
} yield { |
NewerOlder