Coder Social home page Coder Social logo

sasl-compiler's Introduction

#a SASL compiler in Haskell

An implementation of a SASL interpreter in Haskell. This repository came to life as an exercise and a followup to this tweet from Erick Meijer.

I am grateful to him and to all those(see ) who laid such a clear and effective path to learning.

Disclaimer

  • It is a working implementation with some serious limits(see bellow).
  • It is absolutely not a model of Haskell programming style.
  • It is my first Haskell program, first Haskell debugging session, first time use of monads and monad transformers, first parser implementation, first contact with SASL, first contact with a SK reduction machine & lambda calculus
  • It(still) might be useful for somebody else who follows the same path in learning. It took me two and a half weeks and less than 750 lines of code. It was a very steep dive and the ultimate Haskell tutorial.

Examples

Map function:

$ echo "\
map f [1,2,3] where
  map g x = if x = nil then nil else g (hd x) : map g (tl x)
  f x = x * x" | runhaskell Main.hs
result :
(S @ (S @ (K @ S) @ (S @ (S @ (K @ S) @ (S @ (K @ K) @ (K @ S))) @ (S @ (S @ (K @ S) @ (S @ (S @ (K @ S) @ (S @ (K @ K) @ (K @ S))) @ (S @ (S @ (K @ S) @ (S @ (K @ K) @ (K @ K))) @ (S @ (K @ K) @ (K @ S))))) @ (S @ (S @ (K @ S) @ (S @ (S @ (K @ S) @ (S @ (K @ K) @ (K @ S))) @ (S @ (S @ (K @ S) @ (S @ (K @ K) @ (K @ K))) @ (S @ (K @ K) @ (K @ K))))) @ (S @ (K @ K) @  ............................................................................................... and  69000 more  characters.

Same Map , only showing head on a different list:

$ echo "\
hd(map f [3,2,1]) where
  map g x = if x = nil then nil else g (hd x) : map g (tl x)
  f x = x * x" | runhaskell Main.hs
Result:
Num 9

What's in it

  • ParserST.hs - a re-implementation of monad transformers (State, Reader) and the Parser Type
  • Grammar.hs - low level parsing utility based on Monadic Parser Combinators
  • SASL.hs - SASL parser (lexer-parser fronted)
  • SK.hs - the SK reduction machine (compiler-reduction backend)
  • Main.hs - high level utilities and command line interface

The backend uses only a couple of math and boolean Haskell built-in operators. All the rest is handled inside the reduction machine.

Limits

  • where expressions support only maximum two mutually-recursive sub expressions
  • global defs are partially implemented and NOT used
  • error reporting is minimal, probably not very helpful
  • no optimizations whatsoever
  • ; separator not used - relies on indentation

Next steps

Not sure if there is a next, but I would love to work on fixing some of the limits.

References:

sasl-compiler's People

Contributors

adriantofan avatar

Stargazers

netgusto avatar Dwayne Crooks avatar Steven Shaw avatar Oleg Tsybulskyi avatar  avatar Ismaël Mejía avatar Artur avatar Marc Saegesser avatar Hercules Merscher avatar Jon Schoning avatar  avatar

Watchers

James Cloos avatar Ondřej Súkup avatar  avatar

Forkers

guntermueller

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.