This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
unique ability Located d where | |
location : d a -> Location {} | |
unique ability Storage.Distributed d where | |
restore : d a -> a | |
save : a -> d a | |
saveNear : d x -> a -> d a | |
unique type Kit d m a | |
= Empty |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# I version my full namespace tree here, it's a snapshot | |
# of all my current workstreams. If I need to switch | |
# computers, I might just push here, then pull on the | |
# other computer. | |
# `.> push` will go here. | |
GitUrl = "[email protected]:pchiusano/unisoncode" | |
# GitUrl { | |
# | |
# # Some projects I occasionally make PRs against. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- splittable RNG type | |
ability Random where | |
nat : Nat | |
split : {Random} (forall g a. '{Random,g} a ->{g} a) | |
{{ ``Random.natIn i j`` generates a {type Nat} between ''i'' and ''j'', | |
not including ''j''. | |
If ''j'' is less than or equal to ''i'', throws an error. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ability Each where | |
each : [a] -> a | |
Each.toStream.handler : Request {Each} a ->{Stream a} () | |
Each.toStream.handler = cases | |
{ a } -> Stream.emit a | |
{ Each.each as -> resume } -> match as with | |
[] -> () | |
a +: as -> | |
handle resume a with Each.toStream.handler |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Ability to range over all the elements of a list | |
ability Each where | |
each : [a] -> a | |
-- Implementation detail - standard early termination ability | |
ability Abort where abort : x | |
-- Here's a first usage. `each` lets us traverse multiple lists | |
-- elementwise, matching up values at corresponding indices. | |
> handle |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- porting https://hackage.haskell.org/package/splitmix-0.1.0.1/docs/src/System.Random.SplitMix.html | |
-- could use a native popcount / hamming weight instruction | |
roll : Nat -> Nat ->{Random} Nat | |
roll n sides = | |
Nat.sum (List.replicate n '(Random.natIn sides + 1)) | |
-- example, rolling 3 x d8 | |
> Random.splitmix 10349 '(roll 3 8) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- imports, not too exciting | |
use DSeq Empty One Two | |
use Storage save restore | |
use Mem Mem | |
use Remote at await | |
-- These are called watch expressions, any line starting with `>` | |
-- gets evaluated when you save the file (and cached), so you can use | |
-- your scratch file a bit like a spreadsheet. | |
> 1 + 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
unique ability Remote loc task result g where | |
at : loc -> '{Remote loc task result g, g} a -> task a | |
fork : '{g} a -> task a | |
await : task a -> result a | |
cancel : task a -> () | |
location : task a -> loc | |
type Value a = Value a | |
Remote.local.sequential.handler : Request {Remote () Value Value g} a ->{g} a |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Nat is just an index into some internal store | |
-- provided by the handler | |
unique type Source a = Source Nat | |
unique type Sink a = Sink Nat | |
ability Abort where abort : a | |
-- You wouldn't typically program with these operations directly, | |
-- but you can implement `fork` in terms of these operations |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- Code by Dan Doel - https://github.com/unisonweb/unison/issues/1055#issuecomment-565753502 | |
{-# language BangPatterns #-} | |
module POC (C(..), eval0, setup) where | |
import Control.Monad.Primitive | |
import qualified Data.Vector.Generic.Mutable as GM | |
import qualified Data.Vector.Unboxed.Mutable as UM |