Skip to content

Instantly share code, notes, and snippets.

@aavogt
aavogt / Interleaved.hs
Created May 20, 2014 23:07
UU-options ported to lens from lenses
{-# LANGUAGE NoMonomorphismRestriction,
FlexibleInstances,
ScopedTypeVariables,
RankNTypes,
FlexibleContexts #-}
module Options.UU.Interleaved where
import Control.Lens hiding (set)
import Data.Functor.Identity
import Control.Applicative.Interleaved
@aavogt
aavogt / tgpF.R
Last active August 29, 2015 14:02
formula-based interface for tgp
un.model.matrix <- function(partial, frml, df) {
mf <- model.frame(terms.formula(frml), df)
fullDesign <- model.matrix(terms.formula(frml), df)
if (ncol(partial) != ncol(fullDesign))
stop('ncol(partial) != ncol(fullDesign)')
asgn <- attr(fullDesign, 'assign')
cs <- attr(fullDesign, 'contrasts')
j <- 0
{-# LANGUAGE TemplateHaskell #-}
module PartialTypeSigs where
import qualified Data.Map as M
import Data.IORef
import System.IO.Unsafe
import Data.Maybe
import Language.Haskell.TH
@aavogt
aavogt / MkF.hs
Last active August 29, 2015 14:05
quasiquote for defunctionalization
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE TemplateHaskell #-}
module MkF (MkF(..), mkF, mkFInstances) where
import Control.Applicative
import Data.HList.CommonMain
import Language.Haskell.TH.Quote
import Language.Haskell.TH
import Language.Haskell.Meta.Syntax.Translate (toType,toExp)
import qualified Language.Haskell.Exts as E
@aavogt
aavogt / a.c
Last active August 29, 2015 14:05
ghc does not check foreign import types
double f (double x) {
return (x*2);
}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE TypeFamilies #-}
data N = S N | Z
@aavogt
aavogt / IsInstance.hs
Created February 2, 2015 03:50
IsInstance
{-# LANGUAGE OverlappingInstances #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE TemplateHaskell #-}
module IsInstance where
import Language.Haskell.TH
@aavogt
aavogt / Main.hs
Created February 13, 2015 23:36
(incomplete) Haskell Parser done with open recursion & uu-parsinglib
{-# OPTIONS_GHC -fno-warn-missing-fields #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE RankNTypes #-}
module Main where
import Data.Default.Class
import Text.ParserCombinators.UU
import Text.ParserCombinators.UU.Idioms
import Text.ParserCombinators.UU.BasicInstances
@aavogt
aavogt / Main.hs
Created February 14, 2015 07:01
CanMap
{-# LANGUAGE OverlappingInstances #-}
{-# LANGUAGE FunctionalDependencies #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE TypeFamilies #-}
module Main where
import Prelude hiding (map)
import qualified Data.Text as T
import qualified Data.Vector.Unboxed as U
@aavogt
aavogt / HList inferred types.md
Created February 16, 2015 16:05
HList implementation details "leaking"

This is an example inferred type from some code I've written using HList (from darcs) and HListPP:

:t sinkWindow
sinkWindow
  :: (Data.HList.Labelable.LabeledOpticF
        (LabelableTy r4) (Const Int),
      Data.HList.Labelable.LabeledOpticP (LabelableTy r4) (->),
      Data.HList.Labelable.LabeledOpticTo
        (LabelableTy r4) "bgWindow" (->),