Skip to content

Instantly share code, notes, and snippets.

View sevanspowell's full-sized avatar

Samuel Bennett (Evans-Powell) sevanspowell

  • Australia
View GitHub Profile
@sevanspowell
sevanspowell / derivation.nix
Last active February 18, 2019 05:57
Nix docker issue
drv =
pkgs.haskell.lib.addBuildDepends
(pkgs.haskellPackages.callPackage ./default.nix {})
(with pkgs; [ docker ])
;
@sevanspowell
sevanspowell / DynamicReader.hs
Created February 14, 2019 06:47
Abstracting source of function parameters using MonadReader
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE InstanceSigs #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE DeriveFunctor #-}
module DynamicReader where
import Control.Monad.Reader (MonadReader(ask, local), ask, ReaderT(ReaderT), runReaderT)
@sevanspowell
sevanspowell / WhyNoInfer.hs
Last active February 14, 2019 00:32
Type inference limitation?
class HasLoggingRep a where
toLogEntry :: a -> Text
-- ...
where
logInfo :: forall a . HasLoggingRep a => a -> IO ()
logInfo = loggerF logger Info . toLogEntry
-- ...
someFn response = do
logInfo response
@sevanspowell
sevanspowell / ConstraintsOnFunction.hs
Created February 11, 2019 21:48
Constraint Question
module ConstraintsOnFunction (mkLookup) where
type Lookup m = Request -> m Response
mkLookup :: (
AsSomeError e,
MonadCatch m,
MonadError e m,
MonadIO m,
MonadResource m) => Lookup m
@sevanspowell
sevanspowell / issue.hs
Created February 1, 2019 04:49
ScottyT issue
someFn :: b -> m a -> m a
someStack :: ActionT e m a
someStack = do
r <- ask
info = r ^. getInfo
lift $ someFn info _
@sevanspowell
sevanspowell / mtl.md
Created November 20, 2018 00:09
MTL guide

This guide outlines an approach to overcome some problems with concrete monad stacks and monad composition.

The problem

So we're writing some code in IO, and everything is going great:

doStuff :: IO Int

doStuff = do

@sevanspowell
sevanspowell / EmacsTooling.md
Last active July 6, 2022 01:11
A guide to setting up the Haskell tooling for Emacs in a Nix environment.

Running Emacs Haskell Tooling in a Nix environment

A guide to setting up the Haskell tooling for Emacs in a Nix environment.

Suggestions/Contact

mail@sevanspowell.net

Configuration

@sevanspowell
sevanspowell / EmacsTooling.hs
Created November 8, 2018 23:03
A guide to setting up the Haskell tooling for Emacs in a Nix environment.
# Running Emacs Haskell Tooling in a Nix environment
A guide to setting up the Haskell tooling for Emacs in a Nix environment.
## Configuration
### Requirements
You will need the following packages:
@sevanspowell
sevanspowell / 01readerConstraint.hs
Last active October 29, 2018 22:22
Satisfying multiple "Has" constraints
fn
:: ( Monad m
, MonadReader r m
, HasX r m
, HasY r m
, HasZ r m
)
=> m Bool
fn = do
r <- ask
@sevanspowell
sevanspowell / errors.txt
Created October 29, 2018 01:57
ScopedTypeVariables unexpected
• Couldn't match type ‘a’ with ‘a1’
‘a’ is a rigid type variable bound by
the type signature for:
mogel :: forall a. Show a => a -> (String, a)
at src/Types.hs:105:1-48
‘a1’ is a rigid type variable bound by
the type signature for:
b :: forall a1. Show a1 => Maybe a1
at src/Types.hs:108:5-39
Expected type: Maybe a1