Skip to content

Instantly share code, notes, and snippets.

@aavogt
aavogt / Ii.hs
Last active August 29, 2015 14:15
generalization of idiom brackets
{-# LANGUAGE OverlappingInstances #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE UndecidableInstances #-}
module VogtNoApplyAB where
import Control.Applicative
class InfixF a b where
@aavogt
aavogt / MJ.hs
Created March 5, 2015 03:31
dynamic binding is confusing
{-# LANGUAGE TemplateHaskell #-}
module MJ where
import Language.Haskell.TH
x = False
xE = varE (mkName "x") -- dyn "x"
xE' = varE 'x
{- |
>>> :set -XTemplateHaskell
@aavogt
aavogt / TT.hs
Created March 14, 2015 22:42
An Iso that removes a data Thunk if present
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE DataKinds #-}
module TT where
import Control.Lens
data Thunk a = Thunk a deriving Show
@aavogt
aavogt / Append.hs
Last active August 29, 2015 14:17
appending Record records
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE FunctionalDependencies #-}
{-# LANGUAGE TemplateHaskell #-}
@aavogt
aavogt / Olaf.hs
Created April 15, 2015 04:39
another variadic uncurry
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE IncoherentInstances #-}
{-# LANGUAGE OverlappingInstances #-}
{-# LANGUAGE FunctionalDependencies #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE MultiParamTypeClasses #-}
module Olaf where
{- |
@aavogt
aavogt / ForwardVector.hs
Created May 11, 2015 21:32
ad forward mode with unboxed vector
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE TemplateHaskell #-}
module ForwardVector where
import Numeric.AD.Internal.Forward.Double
import Numeric.AD.Mode
import Numeric.AD.Internal.Identity
@aavogt
aavogt / VectorDataFamily.hs
Last active August 29, 2015 14:21
roles are more restrictive (but not for newtype instance)
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE TypeFamilies #-}
import qualified Data.Vector as V
import qualified Data.Vector.Mutable as VM
import qualified Data.Vector.Generic as G
import Data.Coerce
import Control.Monad.Primitive
import Foreign.C
data family MVec (v :: * -> *) :: * -> * -> *
@aavogt
aavogt / Nikolay.hs
Created September 11, 2015 20:23
injectivity problem
{-# LANGUAGE NoMonomorphismRestriction #-}
{-# LANGUAGE TypeFamilies #-}
module Nikolay where
import Control.Lens
-- superclass constraint here says that TtseT is the inverse to TestT,
-- without it, the example attached to test2 fails, since otherwise we
-- could be allowed to add a
--
-- type TestT Double = Char,
--
@aavogt
aavogt / FocusNth.hs
Created December 22, 2015 23:48
FocusNth swapNth
-----------------------------------------------------------------------------
-- |
-- Module : XMonad.Actions.FocusNth
-- Copyright : (c) Karsten Schoelzel <kuser@gmx.de>
-- License : BSD
--
-- Maintainer : Karsten Schoelzel <kuser@gmx.de>
-- Stability : stable
-- Portability : unportable
--
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE DataKinds, FlexibleContexts, TemplateHaskell, TypeFamilies, TypeOperators #-}
import Data.Extensible
import Data.Monoid
import Control.Monad.Identity
mkField "a b"
nilR :: Comp First (Field Identity) :* '[]
nilR = Nil