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
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
View cancel.hs
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE GADTs #-}
{-# OPTIONS_GHC -Wall #-}
module Main where
@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 #-}
View exist.hs
{-# LANGUAGE ExistentialQuantification #-}
data Adder = forall a. Adder
{ increment :: a -> a
, render :: a -> String
, value :: a
}
main :: IO ()
main = do
View lol
```
λ> :set -XPolyKinds -XKindSignatures
λ> undefined :: forall (a :: ka) (b :: kb) (c :: k1 -> k2 -> *). c a b -> c b a
<interactive>:2:61: error:
Illegal symbol '.' in type
Perhaps you intended to use RankNTypes or a similar language
extension to enable explicit-forall syntax: forall <tvs>. <type>
λ> :set -XRankNTypes
λ> undefined :: forall (a :: ka) (b :: kb) (c :: k1 -> k2 -> *). c a b -> c b a
View CompileTimeLiterals.md

Compile Time Literals

I've been kicking an idea around for revamping overloaded literals in Haskell. Please give a thought:

Right now we do runtime fromInteger, fromString, fromList, etc. calls. The types of these functions are Integer -> a, String -> a, etc. These functions are usually partial for more interesting types, and the failure typically occurs at runtime. I propose that we convert the literal at compile-time instead (potentially using quasiquotes), along with new classes that provide function compileLiteral :: literal -> Either String value.

The definition would look like this:

@parsonsmatt
parsonsmatt / ugh.hs
Created Apr 13, 2018
maybe your thinking, "wow, i really want a type class with only two instances" well here you go!! don't export the class and you're *golden*. i mean, write a better error message, but come on
View ugh.hs
-- gross hack so i can lighten the syntax load
class NameOrEntityRef x where
disambiguate :: x -> Either Name EntityRef
instance NameOrEntityRef Name where
disambiguate = Left
instance NameOrEntityRef EntityRef where
disambiguate = Right
View quick-hack.hs
-- Why use `mtl` constraints?
-- well, suppose you've got some tests using `MonadState`, but then that was a
-- mistake, because of the way that Alternative's IO works:
-- you had state rollback! Oh no!
--
-- Fortunately, it is relatively easy to write a state instance that Just Works
-- with IO references, which preserves state across threads and exceptions.
-- And, with GeneralizedNewtypeDeriving, you get all the necessary instance
-- boilerplate for free.
--
You can’t perform that action at this time.