Skip to content

Instantly share code, notes, and snippets.

Avatar

Oskar Wickström owickstrom

View GitHub Profile
@owickstrom
owickstrom / Main.purs
Last active Dec 8, 2016
PureScript record and mutual recursion problem with Instances
View Main.purs
module Main where
import Prelude
import Control.Monad.Eff (Eff)
import Control.Monad.Eff.Console (CONSOLE, log)
type R m = { f Int m Int }
makeDecr m. Monad m R m R m
makeDecr r = { f: \n → if n > 0 then r.f (n - 1) else pure n }
View compile-error.txt
No type class instance was found for
Control.Monad.Monad m0
while checking that expression { path: [ "contact"
]
, GET: handler (\conn ->
...
)
@owickstrom
owickstrom / composing-alt-functions.md
Last active Nov 28, 2016
Composing Alt Functions
View composing-alt-functions.md

What I want is to "compose" functions taking some argument and returning an Alt value, like a -> m b where Alt b. The resulting value should be a function from a -> m b. The implementation below does that, but I was wondering if there's a better way? I'm thinking that maybe I could create a newtype wrapper around these functions, and an Alt instance for that type, but I haven't gotten that to work, and I'm not sure it's a good approach.

@owickstrom
owickstrom / SafeWeb.purs
Last active Nov 13, 2016
Safe web routes in PureScript
View SafeWeb.purs
module SafeWeb where
import Prelude
import Data.Array (filter)
import Data.Leibniz (type (~))
import Data.String (Pattern(Pattern), split, joinWith)
type Path = Array String
pathToHtml :: Path -> String
@owickstrom
owickstrom / TypeSynonymsProblem.purs
Created Oct 29, 2016
PureScript type synonym problem with effect kind
View TypeSynonymsProblem.purs
module TypeSynonymsProblem where
import Prelude
import Control.Monad.Eff (Eff)
import Data.Either (Either)
import Data.Tuple (Tuple(Tuple))
type Foo e a a' b b' = Eff e (Tuple a b) -> Eff e (Tuple a' b')
type Bar e a a' b b' = Eff e (Either a b) -> Eff e (Either a' b')
@owickstrom
owickstrom / Name.idr
Created Oct 13, 2016
Idris String with validation?
View Name.idr
-- A data type wrapping a non-empty string
data Name : Type where
MkName : (s : String) -> (not (s == "") = True) -> Name
-- Some function that expects a valid Name
test : Name -> String
test (MkName s _) = s
-- Usage of that function. Do I need Refl here? Any better way of doing this?
foo : String
@owickstrom
owickstrom / protocols.go
Last active Apr 11, 2016
Protocols sketches for Oden
View protocols.go
//----------//
// SEMIRING //
//----------//
// Types that support addition and multiplication.
protocol Semiring(a) {
add : a -> a -> a
zero : a
mul : a -> a -> a
one : a
View based-on-existing-syntax.lisp
(pkg main)
(import fmt)
;; if expressions
(: fib (int -> int))
(def (fib n)
(if (== n 1)
0
(if (== n 2)
@owickstrom
owickstrom / README.md
Last active Oct 27, 2015
Kashmir Programming Language - Draft
View README.md
@owickstrom
owickstrom / type-system.rkt
Created Oct 12, 2015
Minimalistic type system hack in Racket.
View type-system.rkt
#lang racket
(require "minikanren/mk.rkt")
(struct e/var (name) #:transparent)
(struct e/app (fn param) #:transparent)
(struct e/lam (arg body) #:transparent)
(define (t/fn domain range)
(list ':fn domain range))