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 RawDebtRec = RawDebtRec | |
{ company :: Text | |
, debt :: Int | |
, phones :: [Int] | |
} | |
parseCompany o = o .: "company" | |
<|> o .: "company" >>= (.: "name") | |
parseInt o = parseJSON o <|> (read <$> parseJSON o) |
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 DeriveAnyClass #-} | |
{-# LANGUAGE DeriveGeneric #-} | |
import Generics.Deriving.Monoid | |
import Generics.Deriving.Semigroup | |
import GHC.Generics | |
data Foo = Foo () deriving (Generic, GSemigroup, GMonoid) | |
instance Semigroup Foo where (<>) = gsappend | |
instance Monoid Foo where mempty = gmempty |
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
isSolution w o n e = all isDigit [w,o,n,e] /\ no*won*won == wonewon /\ no != 0 where | |
no = fromDigits [o,n] | |
won = fromDigits [n,o,w] | |
wonewon = fromDigits [n,o,w,e,n,o,w] : [32] | |
isDigit x = 0 <= x /\ x <= 9 | |
fromDigits digits = sum [digit * 10^^exp | digit <- digits | exp <- [0...]] |
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
-- bad: everything in ... is nested | |
do | |
v <- foo | |
case v of | |
Matches v' -> ... | |
_ -> throwError "doesn't match" | |
-- good: ... is not nested | |
do | |
v <- foo |
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 | |
Rank2Types, | |
GADTs, | |
DataKinds, | |
PolyKinds, | |
TypeFamilies, | |
DatatypeContexts, | |
MultiParamTypeClasses, | |
UndecidableInstances, | |
UndecidableSuperClasses |
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 Control.Concurrent | |
import Control.Monad.State | |
import qualified Data.Map as M | |
import System.Exit | |
import XMonad.Core | |
import XMonad.Operations | |
import qualified XMonad.StackSet as W | |
windowIDs :: W.StackSet i l a sid sd -> [a] | |
windowIDs ss |
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 Data.Int | |
import Data.IntMap (IntMap) | |
import qualified Data.IntMap as IM | |
data CellUpdate = CellUpdate | |
{ inputID :: Maybe Int | |
, offset :: Int8 | |
} deriving (Eq, Ord, Read, Show) | |
instance Monoid CellUpdate where mempty = CellUpdate Nothing 0 |
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 Data.List | |
import Data.Maybe | |
import Data.Ord | |
shareArea = 85 | |
pizzaArea size = pi * (size/2)^2 | |
totalPizzaArea = sum . map pizzaArea | |
sufficient area sizes | area < 0 = [[]] | |
sufficient area [] = [] |
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 Control.Monad.Writer hiding (liftIO) | |
import Data.Functor.Compose | |
type InitIO = Compose (Writer (IO ())) IO | |
-- | Do no initialization | |
liftIO :: IO a -> InitIO a | |
liftIO = Compose . pure | |
liftInit :: IO () -> InitIO () |
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 QuantifiedConstraints #-} | |
{-# LANGUAGE TypeFamilies #-} | |
import GHC.Exts | |
class (forall a. A t a => A t [a]) => B t where type A t a :: Constraint | |
instance B t => B [t] where type A [t] a = A t a |