Skip to content

Instantly share code, notes, and snippets.

Matt Parsons parsonsmatt

View GitHub Profile
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 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 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 ()
View sqlite-repro.hs
#!/usr/bin/env stack
-- stack --resolver lts-13.3 script
{-# LANGUAGE EmptyDataDecls #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE QuasiQuotes #-}
View product.hs
{-# language FlexibleInstances, DataKinds, TypeFamilies, TypeOperators, MultiParamTypeClasses, UndecidableInstances, UndecidableSuperClasses, FunctionalDependencies, PolyKinds #-}
import GHC.Exts
import GHC.TypeLits
import Data.Proxy
type family AllC (c :: k -> Constraint) (xs :: [k]) :: Constraint where
AllC _ '[] = ()
AllC c (k ': ks) = (c k, AllC c ks)
View hlist.hs
{-# LANGUAGE GADTs, DataKinds, TypeOperators #-}
data HList xs where
HNil :: HList []
(:::) :: a -> HList as -> HList (a : as)
-- error:
/home/matt/hlist.hs:4:38: error:
Expected kind ‘* -> *’, but a : as has kind [*]
In the first argument of HList, namely (a : as)
In the type HList (a : as)
@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

View build.log
Version 1.8.0, Git revision 18c83fffb10931da3357d8d5e17138c2fefa88b3 x86_64 hpack-0.28.2
2018-06-21 16:40:51.857781: [debug] Checking for project config at: /home/matt/Projects/cardano-sl/stack.yaml
@(src/Stack/Config.hs:853:9)
2018-06-21 16:40:51.857972: [debug] Loading project config file stack.yaml
@(src/Stack/Config.hs:879:13)
2018-06-21 16:40:51.861845: [debug] Decoding build plan from: /home/matt/.stack/build-plan/lts-11.13.yaml
@(src/Stack/Snapshot.hs:164:5)
2018-06-21 16:40:51.861930: [debug] Trying to decode /home/matt/.stack/build-plan-cache/lts-11.13.cache
@(src/Stack/Snapshot.hs:156:32)
2018-06-21 16:40:51.868020: [debug] Success decoding /home/matt/.stack/build-plan-cache/lts-11.13.cache
You can’t perform that action at this time.