Skip to content

Instantly share code, notes, and snippets.

View paf31's full-sized avatar

Phil Freeman paf31

View GitHub Profile
@paf31
paf31 / node-haskell.md
Last active May 14, 2024 03:51
Reimplementing a NodeJS Service in Haskell

Introduction

At DICOM Grid, we recently made the decision to use Haskell for some of our newer projects, mostly small, independent web services. This isn't the first time I've had the opportunity to use Haskell at work - I had previously used Haskell to write tools to automate some processes like generation of documentation for TypeScript code - but this is the first time we will be deploying Haskell code into production.

Over the past few months, I have been working on two Haskell services:

  • A reimplementation of an existing socket.io service, previously written for NodeJS using TypeScript.
  • A new service, which would interact with third-party components using standard data formats from the medical industry.

I will write here mostly about the first project, since it is a self-contained project which provides a good example of the power of Haskell. Moreover, the proces

@paf31
paf31 / unsession.md
Last active August 29, 2015 14:06
PureScript Unsession
@paf31
paf31 / code
Created August 14, 2014 17:50 — forked from emiaj/code
let isEven :: Number -> Boolean
isEven 0 = false
isEven 1 = false
isEven 2 = true
isEven n = isEven(n-1)
@paf31
paf31 / ghcjs-purescript.hs
Created June 29, 2014 19:15
Minimal purescript front-end which compiles with GHCJS
module Main where
import qualified Language.PureScript as P
main = interact compile
where
compile text =
case P.runIndentParser "" P.parseModules "module Prelude where\nmain = \"Hello World\"" of
Left err -> show err
Right modules ->
module LLC
consume : Nat -> List (Maybe Nat) -> List (Maybe Nat)
consume vid (Nothing :: vs) = Nothing :: consume vid vs
consume vid (Just v :: vs) with (vid == v)
| True = Nothing :: vs
| False = Just v :: consume vid vs
data Lolli : Type -> Type -> Type where
mkLolli : (a -> b) -> Lolli a b
@paf31
paf31 / exists.purs
Created May 13, 2014 00:59
Existential types as a library
module Main where
foreign import data Exists :: (* -> *) -> *
foreign import mkExists
"function mkExists(fa) {\
\ return fa;\
\}" :: forall f a. f a -> Exists f
foreign import runExists
@paf31
paf31 / trampoline.purs
Last active August 29, 2015 14:01
Tramampoline!
module Main where
import Debug.Trace
data Trampoline a = Done a | More ({} -> Trampoline a)
instance functorTrampoline :: Functor Trampoline where
(<$>) f (Done a) = Done (f a)
(<$>) f (More k) = More $ \_ -> f <$> k {}
@paf31
paf31 / Deriv.idr
Last active July 20, 2017 07:14
Calculus of types in idris
module Deriv
import Control.Isomorphism
--
-- A type constructor df is the derivative of the type constructor f if for all x and e there exists d such
-- such that
--
-- f (x + e) ~ f x + e * (df x) + e^2 * d
--
@paf31
paf31 / UnderscoreFFI.js
Last active January 2, 2021 06:24
Minimal UnderscoreJS Binding for PureScript
"use strict";
// module UnderscoreFFI
exports.map = function(f) {
return function (arr) {
return require('underscore').map(arr, f);
};
};
@paf31
paf31 / fib.js
Created March 29, 2014 20:49
Fibonnaci sequence in PureScript
var main = function __do() {
var _4 = 1;
var _3 = 1;
return (function () {
while (_ps.Prelude.pure(_ps.Prelude.applicativeFromMonad(_ps.Control_Monad_Eff.monadEff({})))(true)()) {
(function __do() {
var _2 = _4;
var _1 = _3;
_3 = _2 + _1;
_4 = _1;