Skip to content

Comment on Roy — small functional language that compiles to JavaScriptparent

Comments

The option monad example might be closer. I'm having trouble figuring out how to get the value out of it though

       data Option a =
	  Some a | None

        let optionMonad = {
		return: fn x =
		Some x
	  bind: fn x f = match x
		case (Some a) = f a
		case None = None
	}

	let m = (do optionMonad
	  bind x = Some 1
	  let y = 2
	  bind z = Some 3
	  return x + y + z
	)

	match m 
		case (Some x) = console.log x

shows an error Error: Type error: Native is not Option 'dwk

Bug in the type system. Fixed. Roy could be cached so you might need to force a refresh.

AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.