Skip to content

Instantly share code, notes, and snippets.

@mlhaufe
Last active December 18, 2015 08:29
Show Gist options
  • Save mlhaufe/cd0b2b7d4e61f9a69f79 to your computer and use it in GitHub Desktop.
Save mlhaufe/cd0b2b7d4e61f9a69f79 to your computer and use it in GitHub Desktop.
Primarily a brainstorming exercise to test out the feel of the language design thus far.
module
exports #Bool #False #True
def Bool
def False <| Bool
and False -> False
and True -> True
or False -> False
or True -> True
not -> True
def True <| Bool
and True -> True
and False -> False
or True -> True
or False -> True
not -> False
module-manifest
M1 -> </lapis/std/A>
M2 -> <http://example.com/src/B>
module-config
N1 -> M1
N2 -> M2 T1:M1.Foo T2:M1.Bar
app-view
</> -> N1
</Baz> -> N2
module :Int :Bool
exports Expr
data Expr :_ => Expr Int
I value: Int
Add
left: Expr Int
right: Expr Int
Mul
left: Expr Int
right: Expr Int
data Expr :_ => Expr Bool
B value: Bool
Eq
left: Expr Int
right: Expr Int
protocol Expr :a
eval -> a
trait I
eval -> $ value
trait B
eval -> $ value
trait Add
eval -> $ left eval + $ right eval
trait Mul
eval -> $ left eval * $ right eval
trait Eq
eval -> $ left eval = $ right eval
module
exports Expr
data Pair :a :b
Pair
fst: a
snd: b
data Expr :_ => Expr Int
Lit value: Int
Plus
e1: Expr Int
e2: Expr Int
data Expr :_ => Expr Bool
Equals
e1: Expr Int
e2: Expr Int
data Expr :a => Expr a
Cond
e1: Expr Bool
e2: Expr a
e3: Expr a
//FIXME
data Expr :a :b => Expr a
Fst e: Expr (Pair fst: a snd: b)
//FIXME
data Expr :a :b => Expr b
Snd e: Expr (Pair fst: a snd: b)
//FIXME
data Expr :a :b => Expr (Pair a: a b: b)
Tuple
e1: Expr a
e2: Expr b
protocol Expr :a
eval -> a
trait Lit
eval -> $ value
trait Plus
eval -> $ e1 eval + $ e2 eval
trait Cond
eval ; $ e1 eval = True -> e2 eval
eval ; $ e1 eval = False -> e3 eval
trait Equals
eval -> $ e1 eval = $ e2 eval
trait Tuple
eval -> Pair fst: $ e1 eval snd: $ e2 eval
trait Fst
eval -> $ e eval fst
trait Snd
eval -> $ e eval snd
module :Int :String
exports Int
trait Int
fizzBuzz ; 3 divides $ -> "Fizz"
; 5 divides $ -> "Buzz"
; -> `#{$}`
module
exports Pair
data Pair :a :b
Pair left: a right: b
trait Pair
+ Pair :left :right -> Pair left: left + $ left
right: right + $ right
module :String
exports String
trait String
isPalindrome -> $ reverse = self
module :Int
exports Point2
data Point2
Point2 x: Int y: Int
trait Point2
+ Point2 :x :y -> Point2 x: x + $ x
y: y + $ y
-- data introduced by an unfold | anamorphism
-- A Recursive Datatype is the Least Fixpoint of a Functor
data Tree a = Leaf a | Branch (Tree a) a (Tree a)
newtype Tree a = Tree {unNode :: Either a (Tree a, a, Tree a))}
data List a = Nil | Cons a (List a)
newtype List a = List {unCons :: Maybe (a, List a)}
@mlhaufe
Copy link
Author

mlhaufe commented Mar 25, 2014

Pattern Matching: http://lambda-the-ultimate.org/node/2927#comment-43259
http://lambda-the-ultimate.org/node/3096

Predicate Dispatch:
From wikipedia: "...extensions with identical or overlapping predicates created
by different developers may interfere with each other in unanticipated ways.
In this respect it is similar to aspect-oriented programming.

http://c2.com/cgi/wiki?PredicateDispatching

From https://groups.google.com/forum/#!msg/comp.lang.lisp/HQFMhGrKrcg/y3wM893uAwQJ:
"Unfortunately, predicate dispatch doesn't work in
the general case, and it shows in the Clojure solution: There are corner
cases there when two methods are applicable at the same time where the
ways to disambiguate them are only very ad hoc."

/////
I suspect similar issues will arise with arbitrary pattern matching on anonymous structures

//
http://lambda-the-ultimate.org/node/1960#comment-23790
http://www.artima.com/weblogs/viewpost.jsp?thread=166742

@mlhaufe
Copy link
Author

mlhaufe commented Mar 27, 2014

  • Use Lapis syntax for config?
  • *.lpc
  • integrating 3rd party configs?

-use a manifest file separate from the config file

@mlhaufe
Copy link
Author

mlhaufe commented Dec 1, 2014

If a definition has no methods or properties, can it not be constructed?
"You can not instantiate a definition which does not define or inherit methods"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment