Skip to content

Instantly share code, notes, and snippets.

View gist:1a57ae22fe221ef9a67c96dc24b4751f
@Icelandjack
Icelandjack / newtype_wrappers.markdown
Last active Nov 26, 2017
Newtype wrappers for deriving
View newtype_wrappers.markdown

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 Nov 29, 2017
Functor over type functions
View Singletons.hs
{-# 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 / ExtensibleIsomorphisms.markdown
Last active Jan 8, 2018
Encoding Overlapping, Extensible Isomorphisms
View ExtensibleIsomorphisms.markdown
View MonoidToSemigroup.markdown
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
View 14661.md
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 Jan 30, 2018
Response to Oleg Grenrus
View Twitter_Oleg.md
View 14733.hs
{-# Language QuantifiedConstraints #-}
{-# Language GADTs #-}
{-# Language ConstraintKinds #-}
{-# Language MultiParamTypeClasses #-}
{-# Language UndecidableSuperClasses #-}
{-# Language FlexibleInstances #-}
{-# Language UndecidableInstances #-}
{-# Language AllowAmbiguousTypes #-}
data D c where
View gist:3a98d3979879fd9415bbde3761c51760
-- 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