This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE TypeFamilies, KindSignatures, DataKinds, TypeOperators, GADTs, MultiParamTypeClasses, FlexibleInstances, GeneralizedNewtypeDeriving, OverlappingInstances, ScopedTypeVariables, FlexibleContexts #-} | |
import Control.Applicative | |
import Control.DeepSeq | |
import qualified Control.Exception as E | |
-- Closed type family, needs GHC HEAD. | |
type family Minus (e :: *) (es :: [*]) :: [*] where | |
Minus e '[] = '[] | |
Minus e (e ': es) = Minus e es |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE MultiParamTypeClasses, FlexibleInstances, FlexibleContexts, FunctionalDependencies #-} | |
import Control.Monad.Reader | |
class Method o m a f | f -> o m a where | |
on :: (o -> m a) -> f | |
instance Method o m a (o -> m a) where | |
on = id |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import re | |
import sys | |
''' | |
Load a PFM file into a Numpy array. Note that it will have | |
a shape of H x W, not W x H. Returns a tuple containing the | |
loaded image and the scale factor from the file. | |
''' | |
def load_pfm(file): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE MultiParamTypeClasses, TypeFamilies, GeneralizedNewtypeDeriving, FlexibleInstances, LambdaCase, DeriveFunctor, ConstraintKinds #-} | |
import Control.Applicative | |
import Control.Monad.State | |
import Control.Monad.Trans | |
import qualified Data.ByteString as BS | |
import Data.Conduit | |
import Data.Monoid | |
import qualified Data.Sequence as S | |
import Data.Word |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE TypeFamilies, GADTs, DataKinds, TypeOperators, FlexibleInstances, OverlappingInstances, ConstraintKinds, MultiParamTypeClasses, ForeignFunctionInterface #-} | |
import Control.Applicative | |
import Foreign | |
import Foreign.C | |
-- heterogenous list | |
data HList (ts :: [ * ]) where | |
E :: HList '[] | |
(:.) :: t -> HList ts -> HList (t ': ts) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Black magic and GADT serialization | |
I thought it would be a cool exercise to write a simple but flexible RPC system in Haskell. The idea was that the server would have some functions and values available for you to use, and you can assemble them into a function call as you like, or provide your own parameters. In the end, writing the serialization and deserialization code ended up leading to some far more interesting challenges. | |
Some types, such as functions, cannot be serialized so they must be made available on the server. I represented this with the following GADT: | |
```haskell | |
type ValueID = Word32 | |
type TypeID = Word32 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE OverloadedStrings, NamedFieldPuns, LambdaCase #-} | |
import Control.Applicative | |
import Data.List | |
import Data.Map (Map) | |
import Data.Maybe | |
import qualified Data.Map as M | |
import Data.Ord | |
import Data.Text (Text) | |
import qualified Data.Text as T |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE OverloadedStrings #-} | |
module Main(main, toHexNice) where | |
import Control.Monad | |
import Criterion.Main | |
import Data.Bits | |
import Data.Monoid | |
import qualified Data.ByteString as BS | |
import qualified Data.ByteString.Lazy as LBS |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE QuasiQuotes, TemplateHaskell, ScopedTypeVariables #-} | |
module BakedVector where | |
import qualified Data.ByteString.Lazy as BSL | |
import Data.ByteString.Lazy (unpack) | |
import Data.ByteString.Builder (toLazyByteString) | |
import Data.ByteString.Builder.Prim | |
import Foreign.Storable | |
import qualified Data.Vector.Storable as VS |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE DefaultSignatures, LambdaCase #-} | |
import Conduit | |
import qualified Data.ByteString as BS | |
import qualified Data.DList as DL | |
import Data.Monoid | |
import Data.Sequences as S | |
import qualified Data.Vector as V | |
import qualified Data.Vector.Storable as SV | |
import qualified Data.Vector.Unboxed as UV |
OlderNewer