Skip to content

Instantly share code, notes, and snippets.

View tgrospic's full-sized avatar

Tomislav Grospić tgrospic

View GitHub Profile
@tgrospic
tgrospic / SimpleRholangWithContinuations.scala
Last active December 29, 2020 20:25
Simple Rholang with higher-order channels and continuations
// Recordings: https://www.youtube.com/watch?v=syXuWv1PZRg&list=PLniEJXpXl6-qSgCMKT2ocQIYt_BQZe04u&index=12
object rholang {
/**
* This interface represents terms in our Simple Rholang language.
* Everything is a process.
*/
trait Process
@tgrospic
tgrospic / SimpleRholangHigherOrder.scala
Last active July 21, 2020 18:30
Simple Rholang with higher-order channels
object rholang {
/**
* This interface represents terms in our Simple Rholang language.
* Everything is a process.
*/
trait Process
/**
* AST of our Simple Rholang language. It's private and accessible only
@tgrospic
tgrospic / SimpleRholang.scala
Last active July 21, 2020 09:20
Very simple example of Rholang with Set as the state
object rholang {
/**
* This interface represents terms in our Simple Rholang language.
* Everything is a process.
*/
trait Process
/**
* AST of our Simple Rholang language. It's private and accessible only
@tgrospic
tgrospic / RChain-ScalaEd-02.md
Last active July 31, 2020 07:14
RChain Scala Educational Series: Introduction to tagless-final style in Scala: higer-kinded types

RChain Scala Educational Series

Introduction to tagless-final style in Scala: higher-kinded types

The very basic tool in programming is to be able to create a variable or a parameter that we can use in many contexts just by replacing it with different values. This is a strange way to say the definition of Lambda calculus which is the basis for most programming languages today. At least those languages that use functions.

The next few examples will show how we can go from value level functions to type level functions and how is this syntax "distinction" represented in languages like TypeScript, C#, Scala, Haskell and Idris.

Video: https://youtu.be/-p1QqAilZoI

@tgrospic
tgrospic / RChain-ScalaEd-01.md
Last active June 5, 2020 11:29
RChain Scala Educational Series: Tagless-final (ZIO)

RChain Scala Educational Series

Beautiful, Simple, Testable Functional Effects for Scala (tagless-final :))

Excellent post by John A De Goes about the critique of tagless-final style of abstracting over program effects and program execution (control flow).
https://degoes.net/articles/zio-environment

In RChain source code tagless-final style is used (mostly) and knowing what are the limitations and where is the hidden complexity, can be very useful. Notes here should help in easier understanding of the points presented in the post.

There are two popular libraries for functional programming in Scala cats and scalaz. Because cats is used in RChain it's also in this examples.

@tgrospic
tgrospic / REV_balance_chrome_bookmark.html
Last active February 25, 2020 21:15
One click REV balance from the browser
data:text/html,<script>
const revBalance = addr => `
new return, rl(\`rho:registry:lookup\`), RevVaultCh, vaultCh in {
rl!(\`rho:rchain:revVault\`, *RevVaultCh) |
for (@(_, RevVault) <- RevVaultCh) {
@RevVault!("findOrCreate", "${addr}", *vaultCh) |
for (@maybeVault <- vaultCh) {
match maybeVault {
(true, vault) => @vault!("balance", *return)
(false, err) => return!(err)

Keybase proof

I hereby claim:

  • I am tgrospic on github.
  • I am grospic (https://keybase.io/grospic) on keybase.
  • I have a public key ASBAeNTYpzr47xvOjAx-vvnIuZSZCkujsN2nm6lPQIhizwo

To claim this, I am signing this object:

@tgrospic
tgrospic / compose.rho
Last active February 18, 2019 16:08
Rholang compose operators
new compose in {
contract compose(input ...@sends) = {
for(...@inp <= input) {
new apply in {
apply!(inp, sends) |
contract apply(argsc, @[send ...rest]) = {
match rest {
[] => {
// the last contract is the end of composition and it's called with suplied args
// and args returned from previous contract (without return channel)
@tgrospic
tgrospic / ..rchain-network.md
Last active February 12, 2019 11:26
RChain network

RChain network scripts

Download

# Download gist files to `rchain-network` folder
git clone https://gist.github.com/62ef42c4b4557ddc80d2cf80914b2ac4.git rchain-network
# change folder
cd rchain-network
@tgrospic
tgrospic / Parsec.hs
Created January 4, 2019 09:22
Parsec tutorial
module Parser where
-- won't work because type class instances must not be type synonyms
-- type Parsera res = String -> (Either String res, String)
-- data Parser res = Parser (String -> (Either String res, String))
-- parse (Parser p) = p
-- or with `newtype`
newtype Parser res = Parser { parse :: String -> (Either String res, String) }