Giter Club home page Giter Club logo

hs2lazy's Introduction

hs2lazy -- Haskell to Lazy K compiler

What is this?

This is a translator from a subset of Haskell to Lazy K.

How to compile

You can build hs2lazy with GHC by following command:

ghc -o hs2lazy --make Main.hs

How to use

hs2lazy [source files]

If multiple source files are given, they are concatenated in the order specified. Output Lazy K code is written to standard output. Prelude module is not automatically loaded. So, you may specify examples/hs2lazy-prelude.hs first, like following:

hs2lazy examples/hs2lazy-prelude.hs foo.hs >foo.lazy

How to write source code

In Lazy K, input and output streams are represented as infinite lists of numbers (256 represents EOF). Hs2lazy programs handle I/O in similar way.

In Haskell, type of main function is IO (). But in hs2lazy, that is:

main :: Stream -> Stream

The Stream type is defined in hs2lazy-prelude.hs as

data Stream = Stream Char Stream

The input is a infinite stream of characters. For example:

Stream 'f' $ Stream 'o' $ Stream 'o' $ Stream eof $ Stream eof ...

eof is defined as (chr 256).

Streams can be converted to/from strings by fromStream and toStream defined in hs2lazy-prelude.hs. For example, following program reverses the input character-by-character.

main = toStream . reverse . fromStream

Or simply,

main = interact reverse

interact converts a String-to-String function to a Stream-to-Stream function.

License

Type.hs is based on Typing Haskell in Haskell. See Lisence.thih for the license of it.

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.