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 DeriveGeneric, DataKinds, KindSignatures #-} | |
import GHC.TypeLits | |
import Data.Text (Text) | |
import GHC.Generics (Generic) | |
data Field (n :: Symbol) v = Field v | |
data Value t = Value t | |
data Banana = Banana | |
{ shape :: Field "banana-shape" (Value Text) |
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 TypeFamilies, DataKinds, TypeOperators, FlexibleInstances, MultiParamTypeClasses, OverlappingInstances, ScopedTypeVariables #-} | |
import Prelude hiding ((!!)) | |
import GHC.TypeLits | |
newtype Map (k :: [Nat]) v = Map [v] | |
empty :: Map '[] a | |
empty = Map [] | |
add :: Sing k -> v -> Map ks v -> Map (k ': ks) v |
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 TypeFamilies, DataKinds, TypeOperators, FlexibleInstances, MultiParamTypeClasses, OverlappingInstances, ScopedTypeVariables, TemplateHaskell, FlexibleContexts, UndecidableInstances #-} | |
import Prelude hiding (head) | |
import GHC.TypeLits | |
import Acme.NumberSystem | |
numberSystem 10 | |
newtype Queue (k :: Nat) v = Queue [v] deriving (Show) | |
empty :: Queue 0 a |
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 TemplateHaskell, TypeSynonymInstances, FlexibleInstances, MultiParamTypeClasses, UndecidableInstances #-} | |
module SingLens where | |
import Control.Lens | |
import SuperLens ((???), makeLensesPlus) | |
data Foo = Foo { _bar :: String, _baz :: Int } deriving Show | |
makeLensesPlus ''Foo | |
-- | f |
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 scalaz._, Scalaz._ | |
import scalaz.effect._, Effect._ | |
object Main extends SafeApp { | |
override def run(args: ImmutableArray[String]): IO[Unit] = for { | |
_ <- println("hello world").pure[IO] | |
} yield () | |
} |
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 Web.Scotty.Trans | |
import Network.Wai.Middleware.RequestLogger | |
import Network.Wai.Middleware.Static | |
import Text.Blaze.Html.Renderer.Text (renderHtml) | |
import System.Environment | |
import Database.Persist.Sql (SqlPersistT(..), Connection, runMigration, runSqlPersistM, runSqlConn, unSqlPersistT) | |
import Database.Persist.Postgresql (withPostgresqlConn) | |
setup :: ScottyT Text (SqlPersistT (NoLoggingT (ResourceT IO))) () -> IO () | |
setup m = do |
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 Data.Conduit (Conduit, runResourceT, ($$), ($=), (=$=)) | |
import Data.Conduit.Binary (sourceFile) | |
import Data.Conduit.List as CL (consume, map) | |
import Data.CSV.Conduit (Row, intoCSV, defCSVSettings) | |
import Data.Text (Text, unpack) | |
-- data source: http://data.gov.au/dataset/fences-on-public-land | |
mkValuable :: Monad m => Conduit (Row Text) m Double | |
mkValuable = CL.map extractVal |
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 DataKinds, TemplateHaskell, TypeFamilies, QuasiQuotes #-} | |
import TICTACTOE | |
game :: ([tq| x o x | |
o o x | |
☐ ☐ x |]) | |
game = (?) |
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
module JSON (module J, writeJson, readJson, diffJsonFiles) where | |
import Import | |
import Data.Aeson as J | |
import Data.HashMap.Strict as J (lookup) | |
import qualified Data.ByteString.Lazy as B | |
import Data.ByteString.Lazy.UTF8 (toString) | |
import Data.Set (difference, fromList, toList) | |
import qualified Data.HashMap.Strict as HM |
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 OverloadedStrings, FlexibleInstances #-} | |
import Data.String | |
import Unsafe.Coerce | |
import Data.Text | |
instance IsString a => IsString (a -> String) where | |
fromString s = \x -> s ++ (unsafeCoerce x) | |
-- returns "foobar" | |
cool = "foo" "bar" :: String |