Skip to content

Instantly share code, notes, and snippets.

Matt Parsons parsonsmatt

Block or report user

Report or block parsonsmatt

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@parsonsmatt
parsonsmatt / prismatic.hs
Created Jun 5, 2018
I figured out a nice way to pluck exceptions out of a constraint!
View prismatic.hs
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE PartialTypeSignatures #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}
@parsonsmatt
parsonsmatt / no-thanks-acid-state.md
Created Dec 17, 2018
acid state antirecommendation
View no-thanks-acid-state.md

Someone asked whether or not acid-state was production ready. I shared my experiences:

parsonsmatt [11:32 AM] @nikolap it's used by cardano-wallet and Hackage. Based on my experience with acid-state, I'd say it is not a good choice for production data storage. For local desktop apps, SQLite is a much better choice, and for real production apps, Postgresql is king.

parsonsmatt [11:44 AM] acid-state did not have a test suite, at all, until I implemented the very first tests (for TemplateHaskell code generation) earlier this year. It has picked up some tests since then, but I'm still not confident in it's correctness.

It claims to be resilient to unplugging the power cord, but I doubt that, as it's not resilient to Ctrl-C: https://github.com/acid-state/acid-state/issues/79

@parsonsmatt
parsonsmatt / timestamp.hs
Created Aug 6, 2019
How long is your Template Haskell taking to run?
View timestamp.hs
timestamp :: String -> Q a -> Q a
timestamp name action = do
start <- runIO getCurrentTime
runIO $ putStrLn $ "Starting " <> name <> ": " <> show start
a <- action
end <- runIO getCurrentTime
runIO $ do
putStrLn $ "Ending " <> name <> ": " <> show end
putStrLn $ "Elapased " <> name <> ": " <> show (diffUTCTime end start)
pure a
View drf.hs
{-# language DuplicateRecordFields, TypeApplications #-}
module DuplicateRecordFields where
data User = User { name :: String }
data Dog = Dog { name :: String }
-- Works
nameAlias :: User -> String
nameAlias = name
View log.hs
{-# LANGUAGE TypeApplications, GADTs, FlexibleInstances, OverloadedLists #-}
module History where
import Lib
import Control.Monad (join)
import qualified Data.Map as Map
import Data.Map (Map)
import qualified Data.List.NonEmpty as NEL
import Data.List.NonEmpty (NonEmpty(..))
View animal2.sql
-- We're modeling the following Haskell datatype:
--
-- data Animal = Cat Name Age | Dog Name OwnerId
--
-- We're going to factor the common 'Name' field into the animal table.
--
-- The data that is specific for each field will go on a table with that field.
-- First we create the animal_type.
CREATE TYPE animal_type AS ('cat', 'dog');
View setisnotafunctor.hs
{-# LANGUAGE DeriveFunctor #-}
module SetIsNotAFunctor where
import Data.Set (Set)
import qualified Data.Set as Set
-- | A type for annotating a value where equality and ordering only care
-- about the value.
data Ann ann a = Ann { annotation :: ann, value :: a }
View animal.sql
-- First we create the animal_type.
CREATE TYPE animal_type AS ('cat', 'dog');
-- Then we create the animal table with a primary key consisting of an
-- auto-incremented integer and the animal type.
CREATE TABLE animal (
id SERIAL NOT NULL,
type animal_type NOT NULL,
PRIMARY KEY (id, type),
View batch-mtl.hs
{-# LANGUAGE FlexibleInstances, MultiParamTypeClasses, GeneralizedNewtypeDeriving, FlexibleContexts #-}
module Lib where
import Control.Monad.State
import Control.Monad.Writer
import Control.Monad.IO.Class
import Control.Monad.Reader
someFunc :: IO ()
View fundeps.hs
{-# LANGUAGE MultiParamTypeClasses, FunctionalDependencies #-}
module Lib where
class C a b | a -> b
instance C () Int
class Foo a where
foo :: C a b => a -> b -> IO ()
You can’t perform that action at this time.