Skip to content

Instantly share code, notes, and snippets.

View nkpart's full-sized avatar

Nick Partridge nkpart

  • Brisbane, Australia
View GitHub Profile
{-# LANGUAGE PartialTypeSignatures #-}
module Lib
( someFunc
) where
import Diagrams
import Diagrams.Prelude
import Diagrams.Backend.SVG.CmdLine
import Diagrams.Backend.SVG
import System.Process

replace $ with (), and reverse

f $ y 3
f (y 3)

change let to bind, and reverse

@nkpart
nkpart / Consuming.hs
Created August 26, 2015 03:34
Consuming keys from a json object
{-# LANGUAGE NoMonomorphismRestriction #-}
{-# LANGUAGE OverloadedStrings #-}
module Data.Yaml.Extended (module Data.Yaml.Extended, lift) where
import Data.Yaml
import qualified Data.Text as T
import Control.Monad.State.Strict (StateT, runStateT, unless, lift, get, modify)
import qualified Data.HashMap.Strict as HM (null, delete, keys)
import Data.List (intercalate)
doThing :: (MonadTrans t
,MonadFree (MyFreeCache Something) (t m)
,MonadFree (MyFreeCache OtherThing) m
)
@nkpart
nkpart / gist:cc852b43d948a33a04c8
Last active June 18, 2019 14:01
Using ghcid inside of emacs
Pieces you need:
* emacs
* ghcid
ghcid needs to know the height of the terminal, we'll set it explicitly
height = (window-height) - (scroll-margin) - 1
set this height as your term-buffer-maximum-size
@nkpart
nkpart / Err.hs
Last active August 20, 2022 01:20
Lens, Prisms, and Errors.
{-# LANGUAGE NoMonomorphismRestriction #-}
{-# LANGUAGE TemplateHaskell #-}
{-# OPTIONS_GHC -fwarn-missing-methods #-}
module Err where
import Control.Lens
import Control.Monad.Error
import Control.Monad.Error.Lens
-- Here is a fairly typical situation, where we have low level errors in certain
@nkpart
nkpart / CrazyIO.hs
Created February 3, 2015 02:47
CrazyIO - binary deserialization using mmaped I/O and Data.Vector.Storable
{-# LANGUAGE ScopedTypeVariables #-}
module CrazyIO (module CrazyIO, mmapFileByteString) where
import qualified Data.Vector.Storable as V
import qualified Data.ByteString as BS
import qualified Data.ByteString.Internal as BS
import Foreign
import System.IO.MMap
crazyLoad :: forall a. Storable a => FilePath -> Maybe (Int64, Int) -> IO (V.Vector a)
@nkpart
nkpart / Val.hs
Created January 28, 2015 23:26
Reified Fold + AccValidation == Good times
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE RankNTypes #-}
module Val where
import Data.Functor.Compose
import Control.Applicative
-- import Data.Semigroup
-- import Data.List.NonEmpty
import Control.Lens
import Data.Validation
@nkpart
nkpart / gist:f35040bc25686d9f46b5
Created January 27, 2015 22:46
Explaining traverse/mapM
∴ ghci
:iGHCi, version 7.8.3: http://www.haskell.org/ghc/ :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
Prelude> :i traverse
Top level:
Not in scope: ‘traverse’
Perhaps you meant ‘reverse’ (imported from Prelude)
@nkpart
nkpart / fmap.md
Last active December 5, 2024 05:31
fmap . fmap . fmap

fmap . fmap . fmap

Functors and Traversables compose.

You might have seen this statement before. This is how you can take advantage of it.

Composing many fmap calls gives you a function that will drill down into a structure and modify it at a certain depth in that nested structure.