Skip to content

Instantly share code, notes, and snippets.

{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE UndecidableInstances #-}
data One
data Succ n
data IronOre
data Iron
data CopperOre
data Copper
struct One;
struct Succ<T>(T);
trait Pos {
type Add<Other: Pos>: Pos;
}
impl Pos for One {
type Add<Other: Pos> = Succ<Other>;
}
impl<T: Pos> Pos for Succ<T> {
struct One;
struct Succ<T>(T);
trait Pos {
type Add<Other: Pos>: Pos;
}
impl Pos for One {
type Add<Other: Pos> = Succ<Other>;
}
impl<T: Pos> Pos for Succ<T> {
var listSelectors = require('list-selectors');
var fs = require('fs')
module.exports = function(elmsource) {
function makeLine(prefixedName) {
const name = prefixedName.substr(1)
return `${name} = "${name}"`
}
%default total
p_implies_p : p -> p
p_implies_p x = x
data And a b = MkAnd a b
data Or a b = Left a | Right b
p_implies_p_and_p : p -> And p p
#include <stdlib.h>
#include <stdint.h>
#include <stdio.h>
#include <time.h>
uint64_t water_on_pillars(uint64_t pillars[], size_t len) {
if (len < 3) {
return 0;
}
typeSignature =
lazy <| \() ->
sepBy (whitespace *> string "->" *> whitespace) nonFunctionType
|> andThen (
reducer TArrow
>> Maybe.map succeed
>> Maybe.withDefault (fail "expected type, got nothing")
)
reducer : (a -> a -> a) -> List a -> Maybe a
typeSignature =
lazy <| \() ->
sepBy (whitespace *> string "->" *> whitespace) nonFunctionType
|> andThen (
reducer TArrow
>> Maybe.map succeed
>> Maybe.withDefault (fail "expected type, got nothing")
)
reducer : (a -> a -> a) -> List a -> Maybe a
@joonazan
joonazan / gist:bb52254a63f774600b49ca4d14527bf6
Created April 17, 2017 13:20
buggy recursion in parser
typeSignature =
lazy <| \() ->
sepBy (whitespace *> string "->" *> whitespace) nonFunctionType
|> andThen (
reducer TArrow
>> Maybe.map succeed
>> Maybe.withDefault (fail "expected type, got nothing")
)
reducer : (a -> a -> a) -> List a -> Maybe a
@joonazan
joonazan / ParseLibrary.elm
Created April 15, 2017 17:56
Invalid recursion in Elm 0.18 still causes runtime error
module ParseLibrary exposing (typeSignature)
import Combine exposing (..)
import Dict exposing (Dict)
type Type
= TArrow Type Type
| TName String
| TRecord (Dict String Type)