dsls with fold algebras

Post on 27-Nov-2014

440 Views

Category:

Software

2 Downloads

Preview:

Click to see full reader

DESCRIPTION

This presentation shows how to use "fold algebras" to implement a toy DSL for paths

TRANSCRIPT

Writing a DSL with a Fold-Algebra

ScalaSyd

Overview

Fold-algebras

File paths

DSLs tips and tricks

The expression problem

Scala types

I’ve had this problem

Result

Failure Success Pending

Console Html

Screenshot?

Pdf?

The Expression Problem

Add(Lit(1), Lit(2))

The Expression Problem

The Expression Problem

Solved in Java?!?

Data as an ADT

List as a “fold”

List as a “fold”

foldRight

or foldLeft?

then map, filter,

flatMap,…

Data types encodings

Fold-

Algebra

(Nil -> A, (A, List[A]) -> A)

F-Algebra

Nil + (A, List[A]) -> A F[A] -> A

List[A] = Nil + (A, List[A])

A Fold-algebra for directories

Name Name Name Name

A Fold-algebra for directories

return an object

doing what you

want!

A DSL for directories

Create

directorie

s?

What’s in a name?

this is

obviously

correct

What’s in a name?

With

macros!

A DSL for directories

Derived

methods

A DSL for directories

Implicit

class

A DSL for directories

What about files?

A Fold-algebra for files

Extend!

A DSL for files

A DSL for files

What about absolute,

relative paths?

A Fold-algebra for paths

Poor Man’s e

num

A Fold-algebra for paths

Type member

A DSL for relative paths

Singleton

type

A DSL for relative paths

A DSL for relative paths

Type alias

“Conform”

type

A DSL for relative paths

Path-dependent

type

A DSL for relative paths

Path-dependent

type

A DSL for relative paths

Conclusion

Play!Papers!

Present at !

Ps3

top related