Skip to content

Instantly share code, notes, and snippets.

@natefaubion
natefaubion / RecordMerge.index.js
Created March 29, 2024 17:11
Record merge with evidence
// @inline export mergeRecord arity=7
// @inline export mergeRecordRhsSkip arity=1
// @inline export mergeRecordRhsCons arity=5
// @inline export mergeRecordRhsNil always
const mergeRecord = () => () => () => () => () => () => dictMergeRecordRhs => ({merge: a => b => dictMergeRecordRhs.mergeRecordRhs(a)(b)});
const merge = dict => dict.merge;
const test1 = {bar: false, foo: 12};
const test2 = v => ({...v, bar: false});
const test3 = v => ({bar: v.bar, foo: 12});
export {merge, mergeRecord, test1, test2, test3};
@natefaubion
natefaubion / ExampleWalkthrough.purs
Created September 22, 2021 16:35
tidy-codegen livecoding example
module CodegenWalkthrough where
import Prelude
import Control.Alternative (guard)
import Control.Monad.Writer (tell)
import Data.Array as Array
import Data.Foldable (for_)
import Data.Maybe (Maybe(..))
import Data.Newtype (unwrap)
@natefaubion
natefaubion / Main.purs
Last active July 20, 2023 00:02
Record currying
module Main where
import Prelude
import Data.Symbol (class IsSymbol)
import Prim.Row as Row
import Prim.RowList as RowList
import Record as Record
import Type.Proxy
@natefaubion
natefaubion / Main.purs
Last active February 12, 2021 18:57
PS Array Builder
-- Copyright 2021 Nathan Faubion
--
-- Permission is hereby granted, free of charge, to any person obtaining a copy
-- of this software and associated documentation files (the "Software"), to deal
-- in the Software without restriction, including without limitation the rights
-- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-- copies of the Software, and to permit persons to whom the Software is
-- furnished to do so, subject to the following conditions:
--
-- The above copyright notice and this permission notice shall be included in
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>Array slice loop</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/benchmark/1.0.0/benchmark.min.js"></script>
<script src="./suite.js"></script>
</head>
<body>
<h1>Open the console to view the results</h1>
@natefaubion
natefaubion / Main.purs
Created January 2, 2021 22:07
List/Generator
module Main where
import Prelude
import Data.Array as Array
import Data.Lazy as L
import Partial.Unsafe (unsafePartial)
newtype Producer f a = Producer (f (Step f a))
data Step f a = Cons a (Producer f a) | Nil
@natefaubion
natefaubion / Main.purs
Created January 2, 2021 21:41
Array slice
module Main where
import Prelude
import Data.Array as Array
import Partial.Unsafe (unsafePartial)
data Slice a = Slice (Array a) Int Int
fromArray :: forall a. Array a -> Slice a
fromArray arr = Slice arr 0 (Array.length arr)
@natefaubion
natefaubion / CoreFn.java
Created December 23, 2020 17:48
CoreFn Java Codecs
package org.purescript.corefn;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import com.fasterxml.jackson.annotation.JsonSubTypes;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import com.fasterxml.jackson.annotation.JsonTypeInfo.As;
import com.fasterxml.jackson.annotation.JsonTypeInfo.Id;
@natefaubion
natefaubion / Main.purs
Last active August 4, 2020 18:20
run with run
module Main where
import Prelude
import Effect
import Effect.Console
import Run
import Run.Except
import Data.Functor.Variant as VariantF
import Data.String as String
module Main where
import Prelude
import Effect
import Effect.Console
import Effect.Ref as Ref
import TryPureScript
makeCounter :: Effect (Effect Int)