Skip to content

Instantly share code, notes, and snippets.

Avatar

Merijn Verstraaten merijn

View GitHub Profile
@merijn
merijn / NoRankN.hs
Last active Dec 22, 2016
Haskell RankNType example
View NoRankN.hs
module RankN where
data Foo = Foo Int | Bar Double
mangle :: Num a => (a -> a) -> Foo -> Foo
mangle f (Foo i) = Foo (f i)
mangle f (Bar d) = Bar (f d)
{-
NoRankN.hs:6:25:
View ghc-hacking.rst
Authors: Merijn Verstraaten
Date: 2014/11/22

So You Want to Be a Super Cool GHC Hacker?

So you have a pet peeve/bug/feature request that you'd like to see added to GHC. You made sure there was a Trac_ ticket for it, but despite your patient waiting no one is solving your problem. Those selfish GHC hackers!

View gist:dc00bc7cebd6df012c5e
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
module HList where
import Prelude hiding (head, tail, zip)
@merijn
merijn / gist:39dc86e345e87276c523
Last active Jan 2, 2019
Index list in haskell
View gist:39dc86e345e87276c523
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
import GHC.Prim (Constraint)
data Nat = Succ Nat | Zero
@merijn
merijn / MyState.hs
Last active Jan 15, 2021
MyState homework
View MyState.hs
data MyState s a = MyState (s -> (a, s))
get :: MyState s s
get = undefined
put :: s -> MyState s ()
put = undefined
modify :: (s -> s) -> MyState s ()
modify = undefined
@merijn
merijn / Foo.hs
Created Aug 23, 2014
Minimal C main FFI example
View Foo.hs
{-# LANGUAGE ForeignFunctionInterface #-}
module Foo where
import Foreign.C.String
import Foreign.C.Types
foreign export ccall start_server :: CInt -> CString -> IO ()
foreign export ccall start_client :: CString -> IO ()
start_server :: CInt -> CString -> IO ()
@merijn
merijn / gist:6130082
Last active Jan 2, 2019
Type family that disallows certain types for type variables.
View gist:6130082
{-# LANGUAGE ConstraintKinds, DataKinds, PolyKinds, TypeFamilies, TypeOperators #-}
import GHC.Exts (Constraint)
type family Restrict (a :: k) (as :: [k]) :: Constraint where
Restrict a (a ': as) = ("Error!" ~ "Tried to apply a restricted type!")
Restrict x (a ': as) = Restrict x as
Restrict x '[] = ()
foo :: Restrict a [(), Int] => a -> a