Skip to content

Instantly share code, notes, and snippets.

@Icelandjack
Icelandjack / gist:1a57ae22fe221ef9a67c96dc24b4751f
Created September 28, 2017 10:54
TODO Divisible implement later
@Icelandjack
Icelandjack / newtype_wrappers.markdown
Last active November 26, 2017 18:19
Newtype wrappers for deriving

Getting Num, Floating, Fractional from Applicative

newtype WrappedApplicative f a = WrapApplicative (f a)
  deriving 
    (Functor, Show)
  deriving newtype 
    Applicative

instance (Applicative f, Num a) => Num (WrappedApplicative f a) where
@Icelandjack
Icelandjack / Singletons.hs
Last active November 29, 2017 13:08
Functor over type functions
{-# Language StandaloneDeriving, PatternSynonyms, GADTs, UndecidableInstances, ScopedTypeVariables, TemplateHaskell, TypeInType, TypeOperators, TypeFamilies, AllowAmbiguousTypes, InstanceSigs, TypeApplications #-}
import Data.Singletons
import Data.Singletons.Prelude.Base
import Data.Singletons.TH
import Data.Kind
import Control.Arrow ((***))
data Dup :: Type ~> Type
@Icelandjack
Icelandjack / SystemF.markdown
Created December 15, 2017 23:16
Embedding System F
@Icelandjack
Icelandjack / ExtensibleIsomorphisms.markdown
Last active January 8, 2018 16:56
Encoding Overlapping, Extensible Isomorphisms
@Icelandjack
Icelandjack / MonoidToSemigroup.markdown
Last active January 22, 2018 19:16
Monoid to Semigroup
demoteMonoid :: (forall m. Monoid m => m) -> Semigroup m => Maybe m
demoteMonoid k = eval k where
  eval :: MONOID m -> Semigroup m => Maybe m
  eval = getOption . foldMap (Option . Just)

data MONOID a = NIL | SING a | MONOID a :<> MONOID a
  deriving Foldable

instance Monoid (MONOID a) where
@Icelandjack
Icelandjack / 14661.md
Created January 27, 2018 20:43
GHC Trac 14661
class ListLike f where
  nil  :: f a
  cons :: a -> f a -> f a
  (·)  :: f a -> f a -> f a

newtype LL a = LL (forall ff. ListLike ff => ff a)

instance ListLike LL where
 nil :: LL a
@Icelandjack
Icelandjack / Twitter_Oleg.md
Last active January 30, 2018 15:28
Response to Oleg Grenrus
@Icelandjack
Icelandjack / 14733.hs
Created January 31, 2018 14:48
14733.hs
{-# Language QuantifiedConstraints #-}
{-# Language GADTs #-}
{-# Language ConstraintKinds #-}
{-# Language MultiParamTypeClasses #-}
{-# Language UndecidableSuperClasses #-}
{-# Language FlexibleInstances #-}
{-# Language UndecidableInstances #-}
{-# Language AllowAmbiguousTypes #-}
data D c where
@Icelandjack
Icelandjack / gist:3a98d3979879fd9415bbde3761c51760
Created March 18, 2018 14:41
HFree + QuantifiedConstraints
-- Response to
-- https://gist.github.com/sjoerdvisscher/e8ed8ca8f3b6420b4aebe020b9e8e235
-- https://twitter.com/sjoerd_visscher/status/975375241932427265
{-# Language QuantifiedConstraints, TypeOperators, RankNTypes, GADTs, ConstraintKinds, MultiParamTypeClasses, FlexibleInstances, UndecidableInstances, PolyKinds, InstanceSigs #-}
import Data.Coerce
type f ~> g = forall x. f x -> g x