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 ConstraintKinds #-} | |
{-# LANGUAGE DeriveGeneric #-} | |
{-# LANGUAGE FlexibleContexts #-} | |
{-# LANGUAGE FlexibleInstances #-} | |
{-# LANGUAGE MultiParamTypeClasses #-} | |
{-# LANGUAGE PartialTypeSignatures #-} | |
{-# LANGUAGE TemplateHaskell #-} | |
{-# LANGUAGE TypeApplications #-} | |
{-# LANGUAGE TypeFamilies #-} |
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
{- | |
Oh no! You're lost in a twisty maze of IO lifting and unlifting, and you've come to | |
an impossible fork: you're currently in some monad that is `MonadBaseControl IO m`, | |
but you need to call a function in `MonadUnliftIO`. AND you need to call functions | |
in your original monad transformer, too! | |
We can make this work, but it's a bit hairy. | |
MonadUnliftIO is a strictly less powerful type class than `MonadBaseControl IO`, so |
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 reproduction can be played with using `ghcid --allow-eval` | |
{-# language RankNTypes #-} | |
import Control.Monad.ST | |
newtype IdT m a = IdT { unIdT :: m a } | |
-- $> :set -XRankNTypes | |
-- |
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 DuplicateRecordFields, TypeApplications #-} | |
module DuplicateRecordFields where | |
data User = User { name :: String } | |
data Dog = Dog { name :: String } | |
-- Works | |
nameAlias :: User -> String | |
nameAlias = 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 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(..)) |
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
-- 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'); |
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 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 } |
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
-- 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), |
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 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 () |
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 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 () |