Skip to content

Instantly share code, notes, and snippets.

View boj's full-sized avatar

Brian Jones boj

View GitHub Profile
@boj
boj / Service.TypeSpec.hs
Created April 24, 2019 17:24
Fancy Monoids
{-# LANGUAGE OverloadedStrings #-}
module Service.TypesSpec where
--------------------------------------------------------------------------------
import Test.Hspec
import Test.QuickCheck
--------------------------------------------------------------------------------
import Data.List (nub)
import Data.Text (Text)
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE OverloadedStrings #-}
module Main where
import Control.Monad.Reader
data AppContext = AppContext { a :: String, b :: Int }
newtype AppT a = AppT { runAppT :: ReaderT AppContext IO a }
{-# LANGUAGE OverloadedStrings #-}
module Main where
import Control.Monad.Reader
-- a basic IO function
f :: IO String
f = return "string"
@boj
boj / Lifty.hs
Created February 20, 2019 23:03
module Main where
import Control.Monad.Writer
import Control.Monad.Except
import Data.Functor.Identity
f :: Monad m
=> (String -> String -> m String)
-> String
-> String
@boj
boj / JWT.hs
Created February 20, 2019 22:52
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE NoMonomorphismRestriction #-}
module Main where
import Control.Monad.IO.Class (MonadIO, liftIO)
import Crypto.JOSE (Error)
import Crypto.JOSE.JWK (JWK)
import Data.Aeson (FromJSON, ToJSON, decode)
@boj
boj / Main.hs
Created February 13, 2019 19:22
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE OverloadedStrings #-}
module Main where
import Control.Monad.IO.Class (liftIO)
import Crypto.JOSE (Error)
import Crypto.JOSE.JWK (JWK)
import Data.Aeson (FromJSON, ToJSON, decode)
import Data.ByteString (ByteString)
@boj
boj / Pav.hs
Created January 4, 2019 18:43
Pav based Haskell typeclasses
module Main where
import Data.Monoid
data Pav a = Pav a | EmptyPav deriving (Show)
instance Semigroup Int where
a <> b = a + b
instance Monoid Int where
mappend a b = a + b
@boj
boj / Meh.hs
Created December 6, 2018 23:48
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
module Main where
import Control.Monad.IO.Class
import Control.Monad.Reader
newtype A a = A { runA :: IO a } deriving (Functor, Applicative, Monad, MonadIO)
newtype B a = B { runB :: ReaderT () IO a } deriving (Functor, Applicative, Monad, MonadIO)
@boj
boj / Fix.hs
Created November 9, 2018 01:09
Haskell Constraint Matches Instance Declaration
{-# LANGUAGE EmptyDataDeriving #-}
data DbNames deriving (Eq, Ord, Show)
@boj
boj / Main.hs
Created October 25, 2018 07:32
Haskell Partial Application Example
module Main where
f :: Int -> String -> String
f n a = mconcat . take n . repeat $ a
g :: String -> String -> String
g a b = b <> " " <> a
z :: (String -> String) -> String
z f = f "world"