Skip to content

Instantly share code, notes, and snippets.

@i-am-tom
i-am-tom / Tree.purs
Last active February 1, 2019 18:57
A labelled, uninterestingly-heterogeneous rose tree implementation in PureScript, with a little dash of Coyoneda.
module Data.Labelled.Tree where
-- Traditionally, we express a rose tree with a structure along the lines of
--
-- ```
-- data RoseTree a
-- = RoseTree a (Array (RoseTree a))
-- ```
--
-- As with many of our favourite "Haskell containers", this comes with an
@i-am-tom
i-am-tom / Record.hs
Last active April 2, 2019 08:46
A tutorial in record manipulation.
{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE FunctionalDependencies #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}
@i-am-tom
i-am-tom / Record.hs
Created January 14, 2019 22:14
Declarative record migration.
{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE FunctionalDependencies #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
@i-am-tom
i-am-tom / Oops.hs
Last active March 26, 2019 12:30
Tracked (and dispatchable) exception-handling with classy variants.
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE FunctionalDependencies #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE UndecidableInstances #-}
@i-am-tom
i-am-tom / Sigma.hs
Last active December 18, 2018 14:18
Sigmaltons
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE TypeFamilyDependencies #-}
module Sigma where
import Data.Kind (Type)
type family Sing (i :: k) = (o :: Type) | o -> i
@i-am-tom
i-am-tom / Day1.hs
Last active December 3, 2018 18:37
Advent of Code
{-# LANGUAGE TypeApplications #-}
module Day1 where
import Control.Monad (foldM)
import Data.Coerce (coerce)
import Data.Functor ((<&>))
import Data.Monoid (Sum (..))
import Data.Set (Set, empty, insert, member)
frequencies :: IO [Sum Integer]
@i-am-tom
i-am-tom / OneTypeFamily.hs
Last active November 23, 2018 16:10
Falling well and truly off the rails.
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeInType #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE UndecidableInstances #-}
module Deriving where
import Data.Kind
import Data.Proxy
@i-am-tom
i-am-tom / Deriving.hs
Last active November 16, 2018 18:44
Deriving generic validators from types.
{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE ApplicativeDo #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE DerivingVia #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GeneralisedNewtypeDeriving #-}
@i-am-tom
i-am-tom / Lib.hs
Created October 26, 2018 17:08
Converting sums to products.
{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE RankNTypes #-}
@i-am-tom
i-am-tom / Coherence.hs
Created October 25, 2018 09:27
Another love letter to {-# INCOHERENT #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
-- | Nothing very serious.
--
-- >>> 5 Years
-- Years 5
--