View NatMatch.scala
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
package dev.posco.nui | |
import scala.compiletime.{erasedValue, error, ops, requireConst} | |
object NatExample { | |
sealed trait Nat | |
object Nat { | |
case object Zero extends Nat | |
case class Succ[N <: Nat](prev: N) extends Nat |
View ioloop.scala
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
package ioloop | |
object IOLoop { | |
enum Res[+A] { | |
case Done(a: A) | |
case FlatMap[A, B](prev: Res[B], fn: B => Res[A]) extends Res[A] | |
case Recurse[A, B](arg: A, loop: (A => Res[B]) => (A => Res[B])) extends Res[B] | |
def flatMap[B](fn: A => Res[B]): Res[B] = | |
FlatMap(this, fn) |
View typed_record.scala
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
package example | |
object RecMap { | |
object Record { | |
// use this scope to bound who can see inside the opaque type | |
opaque type Rec[A <: Tuple] = Map[String, Any] | |
object Rec { | |
type HasKey[A <: Tuple, K] = |
View NatInc.scala
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
package example | |
sealed trait Nat | |
case object Zero extends Nat | |
case class Succ[N <: Nat](n: N) extends Nat | |
type Inc[N <: Nat] <: Nat = | |
N match { | |
case Zero.type => Succ[Zero.type] | |
case Succ[n] => Succ[Inc[n]] |
View sized_list.scala
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
package sizetypes | |
import scala.compiletime.ops.int | |
type LessThan[A <: Int] = | |
A match | |
case 0 => Nothing | |
case _ => | |
int.-[A, 1] | LessThan[int.-[A, 1]] | |
View Nat.py
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
def times2(___bn2): | |
if ___bn2 == 0: | |
return 0 | |
else: | |
___a0 = ___bn2 - 1 | |
___bprev2 = ___a0 | |
return times2(___bprev2) + 2 |
View wordcount.scala
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
package dev.posco.hiona.jobs | |
import cats.effect.{Blocker, IOApp, IO, ExitCode} | |
import dev.posco.hiona._ | |
import java.nio.file.Paths | |
object WordCountSimple extends IOApp { | |
case class Record(key: String, value: Long) | |
def run(args: List[String]): IO[ExitCode] = |
View Cargo.toml
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
[package] | |
name = "hello" | |
version = "0.1.0" | |
authors = ["P. Oscar Boykin <boykin@pobox.com>"] | |
edition = "2018" | |
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | |
[dependencies] | |
csv = "1.1" |
View checked_exceptions_in_scala.scala
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
/* | |
* Scala 3 is getting union types, so it occurs to me we could use these to model checked exceptions | |
* on the JVM. | |
* This is a sketch of how this could work | |
*/ | |
// on the JVM, any operation could through some Error (OOM for instance) | |
// so annotating should be some kind of Exception, not any Throwable | |
type Throws[E <: Exception, +A] |
View WithTC.scala
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
package WTC | |
import cats._ | |
import cats.implicits._ | |
abstract class WithTC[TC[_[_]], A] { | |
type F[_] | |
val value: F[A] |
NewerOlder