Skip to content

Instantly share code, notes, and snippets.

@parsonsmatt
parsonsmatt / drf.hs
Last active July 30, 2019 14:49
I'm upset
{-# language DuplicateRecordFields, TypeApplications #-}
module DuplicateRecordFields where
data User = User { name :: String }
data Dog = Dog { name :: String }
-- Works
nameAlias :: User -> String
nameAlias = name
{-# 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(..))
{-# 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 }
-- 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');
-- 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),
{-# 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 ()
{-# 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 ()
#!/usr/bin/env stack
-- stack --resolver lts-13.3 script
{-# LANGUAGE EmptyDataDecls #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE QuasiQuotes #-}
{-# 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)
{-# 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)’