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
data MappingRow = MappingRow { date :: Date, prod :: Sym, tenor1v :: Sym, tenor2v :: Sym } deriving Show | |
convertRow :: [MySQLValue] -> IO MappingRow | |
convertRow sqlRow = eitherStrToMonadError $ | |
-- I have to define some otherwise-useless x just so that I can use guards. Is there a better way? | |
-- Why is the syntax for guards so restrictive? | |
let x | |
| [MySQLInt32U date, MySQLText prod, MySQLInt16U tenor1v, MySQLInt16U tenor2v] <- sqlRow = do | |
prod' <- maybeToEither "Bad symbol" $ symFromStrMay prod | |
let (tenor1v', tenor2v') = |
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
class (Eq a, Hashable a, Show a, Typeable a) => Computable a where | |
toCCode :: a -> CCode | |
toCCodeMay :: a -> Maybe CCode | |
toCCodeMay = map Just toCCode | |
defValue :: a | |
isDefValue :: a -> Bool | |
isDefValue = (== defValue) | |
instance Computable Foo where | |
... |
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.Except | |
bar :: MonadIO m => m Int | |
baz :: Int -> Either String Int | |
foo1 :: IO () | |
foo1 = runExceptT >=> either fail pure $ do | |
a <- bar | |
b <- liftEither . baz $ 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 OverloadedStrings #-} | |
import ClassyPrelude | |
import Control.Lens | |
newtype Name = Name Text deriving (Monoid, Semigroup, IsString, Show) | |
newtype LongName = LongName Text deriving (IsString, Show) | |
data Foo1 = Foo1 Int Name Bool deriving Show |
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
-- This problem actually goes out of memory. | |
main :: IO () | |
main = do | |
let oom :: Vector Char | |
oom = V.replicate 1000000000000 'a' | |
l = length oom | |
print l |
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, KindSignatures, FlexibleInstances, MultiParamTypeClasses, TypeApplications #-} | |
module Lib where | |
import ClassyPrelude | |
import GHC.Records | |
import GHC.TypeLits (Symbol) | |
instance forall (field :: Symbol) r a. HasField field r a => HasField field (Identity r) a where | |
getField (Identity x) = getField @field 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 AllowAmbiguousTypes, ConstraintKinds, FlexibleInstances, KindSignatures, RankNTypes, TypeApplications #-} | |
module Lib3 where | |
import ClassyPrelude | |
import Data.Kind (Constraint) | |
type MyConstraint a = (Show a, Monoid a) | |
-- The error goes away if I replace 'MyConstraint with Show' on L10,18, but I want to be able to express multiple constraints on L18. | |
fooF :: forall a. MyConstraint a => a -> String |
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
class FieldPathPart (k :: Symbol) r where | |
fieldPathPart :: Proxy k -> r -> Maybe PathBuilder | |
-- I want this instance to be chosen instead of the other one wherever the constraints are met. GHC complains about duplicate instances. | |
instance {-# OVERLAPPING #-} (Has k v r, B.Binary v, Show v) | |
=> FieldPathPart (k :: Symbol) r where | |
fieldPathPart _ r = | |
let v = get (Proxy :: Proxy k) r | |
in Just (B.put v, tshow 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 DataKinds, FlexibleInstances, OverloadedLabels, TemplateHaskell, TypeFamilies, TypeOperators #-} | |
module Lib3 where | |
import ClassyPrelude | |
import Language.Haskell.TH | |
reifyQ :: Name -> Q Exp | |
reifyQ name = do | |
r <- reify name |
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, FlexibleInstances, TemplateHaskell, TypeFamilies, TypeOperators #-} | |
module LabelsTH where | |
import ClassyPrelude | |
import Language.Haskell.TH | |
import Labels ((:=)) | |
typeForFieldname :: String -> Type | |
typeForFieldname "x" = ConT ''Int |