Skip to content

Instantly share code, notes, and snippets.

View frasertweedale's full-sized avatar

Fraser Tweedale frasertweedale

View GitHub Profile
@frasertweedale
frasertweedale / bfpg-news-2019-06.rst
Last active June 11, 2019 08:20
BFPG news 2019-06
@frasertweedale
frasertweedale / parse.hs
Created May 24, 2019 00:08
Arithmetic expression operator precedence parsing
{-# LANGUAGE OverloadedStrings #-}
import Control.Applicative
import Data.Char (isAlpha)
import Data.Attoparsec.ByteString.Char8
data Expr = Mul Expr Expr | Add Expr Expr | Lit Char | Var Char deriving Show
expr = (add <|> mul <|> (Var <$> satisfy isAlpha) <|> (Lit <$> satisfy isDigit)) <* endOfInput
@frasertweedale
frasertweedale / Example.hs
Created February 27, 2019 03:07
union maps, reject and collect duplicate keys
module Example where
import Data.Map
import Data.Validation
import Data.List.NonEmpty (NonEmpty((:|)))
-- | Merge maps rejecting duplicate keys, which are collected in the 'Failure' value
--
-- >>> awsm (fromList [('a', 1)]) (fromList [('b', 2)])
-- Success (fromList [('a',1),('b',2)])
@frasertweedale
frasertweedale / news.rst
Last active February 11, 2019 09:12
BFPG news 2019-02
@frasertweedale
frasertweedale / news.rst
Last active October 9, 2018 04:53
BFPG news 2018-10-09
@frasertweedale
frasertweedale / Interval.hs
Last active August 27, 2018 14:37
type-level range enforcement
{-|
This module provides types for clamping data in a given range or
interval.
-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE ScopedTypeVariables #-}
@frasertweedale
frasertweedale / test.rst
Last active June 8, 2018 05:01
GitHub ReST feature test

What does GitHub ReST renderer support?

Monospace
text
block.
@frasertweedale
frasertweedale / Poly.hs
Last active April 26, 2018 05:17
type coercion with poly-kinded phantom type
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE DataKinds #-}
module Poly where
data Mode = Mode1 | Mode2
data Action ctx a = Action
-- | Coerce the phantoms (poly-kinded)
@frasertweedale
frasertweedale / ldapdn.c
Last active April 16, 2018 05:39
DN parsing programs (NSS, openldap)
#include <stdio.h>
#include <stdlib.h>
#include <ldap.h>
int main(int argc, char **argv) {
if (argc < 2) {
printf("Usage!\n");
exit(1);
}
@frasertweedale
frasertweedale / news-2018-04-10.rst
Last active April 10, 2018 04:45
BFPG news 2018-04

Conferences/events

  • YOW! Night Tues April 17
    • Linda McIver (Australian Data Science Education Institute)