Skip to content

Instantly share code, notes, and snippets.

View ceedubs's full-sized avatar

Cody Allen ceedubs

  • central Indiana, USA
View GitHub Profile
@ceedubs
ceedubs / scratch.u
Created June 3, 2024 13:07
Unison custom partial ability handler
handleRemoteCustom : '{g, Remote} r -> {g, Remote} r
handleRemoteCustom =
go : forall r. '{g, Remote} r -> {g, Remote} r
go thunk = handle !thunk with cases
{ r } -> r
{ time.now! -> k } ->
res = todo "what do you want to do for time?"
go '(k res)
{ Promise.tryWrite x y -> k } ->
res = Promise.tryWrite x y
@ceedubs
ceedubs / unknown_combinator.md
Created May 10, 2023 01:29
`reference to unknown combinator` when pretty-printing function

reference to unknown combinator when pretty-printing function

This transcript shows an example of a function that returns the expected result but causes the pretty-printer to fail with the error reference to unknown combinator: #0lib3

.> builtins.merge

There is probably a way to reproduce this issue with less code, but I ran into it while writing some recursion scheme code which I have simplified a bit for this transcript:

@ceedubs
ceedubs / transitive-update-issue.md
Created November 2, 2021 21:22
Unison transitive update issue

We create one (oops with the wrong value).

one = "two"
.>add
@ceedubs
ceedubs / dbintegrity.md
Created October 15, 2021 21:09
DatabaseIntegrityError when changing from structural to unique in scratch file
.> alias.type ##Text Text
structural ability MyAbility where
  foo: Text
@ceedubs
ceedubs / cycles.md
Created September 21, 2021 15:17
Unison: error-prone update behavior with code cycles

When there is a cycle in code (ex: function f calls function g and function g calls function f), if you edit only one of the functions at a time and then run a ucm update, it won't fully propagate the change that was made.

In this example, isEven and isOdd call into each other. They are both created in a scratch file and added at the same time, and everything works as one would expect.

isEven : Nat -> {Stream Text} Boolean
isEven n =
  emit ("isEven called with " ++ (Nat.toText n))
  if n Nat.== 0 then true
 else if n Nat.== 1 then false
@ceedubs
ceedubs / applying-non-function.md
Last active September 15, 2021 15:10
Unison runtime crash: applying non-function: Enum ##Boolean 1

background: data structures and functions

{{
A data structure that holds the arguments that you would pass to foldLeft.

The one difference is that there is an extra "extract" function at the end that is to be run after
the foldLeft completes. This can be useful when the fold needs to maintain some state during the
fold but you don't want to include it in the final result.
}}
@ceedubs
ceedubs / unison-tdd.md
Created September 14, 2021 21:59
content-addressed updates kind of break TDD/implementation stubs
fn1 : Nat -> Text
fn1 = .base.todo

fn2 : Nat -> Text
fn2 = .base.todo
.> add
@ceedubs
ceedubs / constructor-unit-printing-bug.md
Created September 13, 2021 14:04
Unison pretty-printer bug: Unit applied to type constructor is printed with !

pretty printer: Unit applied to type constructor is printed with !

Some 3 is printed as Some 3, but Some () is printed as !Some.

I'm guessing that there's some logic to pretty-print unit being applied to a thunk (a function) that is also being applied to type constructors.

> Some 3

> Some ()
@ceedubs
ceedubs / FreeAlt.scala
Created December 17, 2019 02:48
Free Alternative in Scala
// Attempted port from http://hackage.haskell.org/package/free-5.1.3/docs/Control-Alternative-Free.html
// Hopefully I did it right, but no guarantees
// DISCLAIMER: definitely not stack-safe in Scala
import cats.{Alternative, Applicative}
import cats.implicits._
sealed abstract class AltF[F[_], A] extends Serializable {
import AltF._
def map[B](f: A => B): AltF[F, B] = this match {

Keybase proof

I hereby claim:

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

To claim this, I am signing this object: