Skip to content

Instantly share code, notes, and snippets.

@Cedev
Cedev / structuralEquality.hs
Created September 21, 2015 03:58
Generic typeclass machinery to reason about functors ignoring their arguments
{-# LANGUAGE DefaultSignatures #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE DeriveGeneric #-} -- Only needed for the DSL example
import GHC.Generics
-- Data types that are constant and uninteresting
class Eq a => Const a
@Cedev
Cedev / nested dos.hs
Created April 16, 2017 05:07
nested dos
main = do
chars <- getLine
let otherchars = do
a <- chars
b <- chars
[a] ++ [b]
putStrLn otherchars
@Cedev
Cedev / tape.hs
Created July 19, 2017 01:28
tape comonad
{-# language DeriveFunctor #-}
{-# language FlexibleInstances #-}
import Data.Function
class Functor w => Comonad w where
extract :: w a -> a
duplicate :: w a -> w (w a)
kfix :: ComonadApply w => w (w a -> a) -> w a
@Cedev
Cedev / structrally-free-alternative.hs
Created August 13, 2017 02:12
structurally correct free alternative
{-# Language GADTs #-}
{-# Language DataKinds #-}
{-# Language KindSignatures #-}
{-# Language ViewPatterns #-}
{-# Language RankNTypes #-}
{-# Language ScopedTypeVariables #-}
import Control.Applicative
@Cedev
Cedev / hklist.hs
Created September 12, 2017 15:06
Heterogenous list (product) that applies a type
{-# LANGUAGE PolyKinds, DataKinds, GADTs, TypeOperators, ConstraintKinds, RankNTypes, MultiParamTypeClasses, FlexibleInstances, FlexibleContexts, UndecidableInstances #-}
import Data.Proxy
import Data.Functor.Identity
import GHC.Exts (Constraint)
data HKList :: (k -> *) -> [k] -> * where
Nil :: HKList f '[]
(:*) :: f x -> HKList f xs -> HKList f (x ': xs)