Skip to content

Instantly share code, notes, and snippets.

View zwilias's full-sized avatar

Ilias Van Peer zwilias

View GitHub Profile
type Dict k v
= Empty
| Node Int k v (Dict k v) (Dict k v)
balance : Dict k v -> Dict k v
balance dict =
case dict of
Empty ->
dict
nodeDecoder : Decoder Node
nodeDecoder =
oneOf
[ intNodeDecoder
, stringNodeDecoder
]
intNodeDecoder : Decoder Node
intNodeDecoder =
nodeDecoder : Decoder Node
nodeDecoder =
oneOf
[ intNodeDecoder
, stringNodeDecoder
]
intNodeDecoder : Decoder Node
intNodeDecoder =
type alias HasAnInt = { foo : Int }
badExample : HasAnInt -> HasAnInt
badExample record =
{ record | foo = toString record.foo }
{- Since we're changing the type, we need to give the correct
type annotation for the new return value
-}
thisWorks : HasAnInt -> { foo : String }
{- This is what the runtime passes in -}
type alias UnsafeFlags =
{ browser : Maybe String
, version : Maybe String
, randomSeed : Int
}
{- And this is what we want to work with -}
type alias Flags =
{ browser : String
module AvlTree exposing (..)
{- Using these definitions, it is impossible to construct an imbalanced binary tree -}
{- a Node encodes a single Node:
- holding a value of type `a`
- with the type of a tree of (height - 1) `t1`
- and the type of a tree of (height - 2) `t2`
-}
@zwilias
zwilias / eliminateRedundantAStar.js
Created October 31, 2017 13:13
Codeshift transformation to eliminate redundant A* calls (i.e. where the number of arguments matches the arity of the function)
module.exports = function(fileInfo, api, options) {
var source = fileInfo.source,
shift = api.jscodeshift,
shiftSource = shift(fileInfo.source);
var functionMakers = ["F2", "F3", "F4", "F5", "F6", "F7", "F8", "F9"];
var functionCallers = ["A2", "A3", "A4", "A5", "A6", "A7", "A8", "A9"];
var arities = {};
shiftSource
module Json.Decode.Completion exposing (..)
import Json.Decode as Decode exposing (Value)
import Json.Encode as Encode
import List.Nonempty as Nonempty exposing (Nonempty(Nonempty))
type alias Errors =
Nonempty Error

Keybase proof

I hereby claim:

  • I am zwilias on github.
  • I am zwilias (https://keybase.io/zwilias) on keybase.
  • I have a public key ASDRDv6WlRFB1C6K7jeWO0b9OFk8CDT8Z_uswJAFqrkl2go

To claim this, I am signing this object:

@zwilias
zwilias / LLRBmap.elm
Created March 13, 2018 20:47
Tail recursive `map` for Dict.LLRB. Slow, but hey, it works.
map : (k -> a -> b) -> Dict k a -> Dict k b
map f dict =
case dict of
Leaf ->
Leaf
Node c k v l r ->
mapHelper f { key = k, color = c, value = f k v, state = Both l r } []