Skip to content

Instantly share code, notes, and snippets.

View aaronlevin's full-sized avatar

Aaron Levin aaronlevin

View GitHub Profile
@aaronlevin
aaronlevin / finally_crud.hs
Created January 5, 2015 20:07
Free CRUD as a library
-- | at the end of this post (http://aaronlevin.ca/post/106721413033/type-families-make-life-and-free-monads-simpler) I conjectured
-- if it would be possible to expose the Free Crud monad as a library (for some definition of the term). Thanks to a huge help
-- from @a_cowley, I think I'm converging on an idea. All the hard stuff was suggested to me by anthony!
-- | kitchen sink of extensions
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
@aaronlevin
aaronlevin / crud.idr
Created January 6, 2015 05:23
Baby's first dependent type: Free Crud in Idris
module freecrud
-- | a really crud(e) and naive attempt at porting over "dependently"-typed haskell code to idris.
-- original haskell code here: https://gist.github.com/aaronlevin/437ceac6acc344f86ef9
-- This is my first idris "program."
-- | crud lib
data CrudVerb = Create | Read
@aaronlevin
aaronlevin / haskell-project.nix
Last active August 29, 2015 14:13
Nix n00b templates
# This template will give you a prompt with:
# - ghc
# - cabal
# - ghc-mod
# - the libraries: free, mtl, transformers
#
# to run: nix-shell haskell-project.nix
#
# to specify specific version of haskell, you can:
# nix-shell --arg haskellPackages 'with import <nixpkgs> {}; haskellPackages_ghc783_profiling'
@aaronlevin
aaronlevin / sql-servant.hs
Last active August 29, 2015 14:13
Sql Servant
-- | playing around with a possible postgresql-simple plugin for servant
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
@aaronlevin
aaronlevin / 01-recap.hs
Last active August 29, 2015 14:14
Free CRUD pt. II
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
module FreeCrud where
-- | some user types
@aaronlevin
aaronlevin / nixffi.md
Last active August 29, 2015 14:14
nix learnings

Recently had some trouble with nix. I was trying to write a Haskell ffi wrap around the micro-ecc lib. After doing this successfully, I wanted my library to work if micro-ecc was correctly installed somewhere on your system. I had the following two directories:

$ ls
micro-ecc
hs-micro-ecc

In micro-ecc I had a fairly vanilla nix expression that looked like:

@aaronlevin
aaronlevin / phantom-type-alternative.hs
Created February 13, 2015 16:14
Is this fundamentally any different than normal phantom types?
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE TypeFamilies #-}
{- Is this fundamentally any different than regular phantom types ala https://wiki.haskell.org/Phantom_type ?
-}
@aaronlevin
aaronlevin / eq-const-type-fam-codo.hs
Created February 14, 2015 05:50
Using Equality Constraints to put Constraints on elemts in a Type Family's CoDomain
-- | I wanted to encode the json key for a payload type as type-level strings
-- one can use equality constraints to resolve type family mappings
data SomeData = SomeData
type family Key (a :: *) :: Symbol where
Key SomeData = "some_data"
-- | here we use equality constrains to resolve `k` to the type-level mapping
-- of SomeData a. then we can restrict `k` to some other constraint (in this
@aaronlevin
aaronlevin / proxy-aeson.hs
Created February 17, 2015 17:36
Use `Data.Reflection` to deserialized type-encoded json strings into `Proxy`
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeFamilies #-}
module Main where
import Control.Monad
import Data.Aeson
import qualified Data.Aeson as A
@aaronlevin
aaronlevin / patterns-not-matched.hs
Last active August 29, 2015 14:15
patterns not matched
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE TypeFamilies #-}
module GADTS where
-- Some universe of types
data Universe = A
| B