All Projects → chrisdone → Duet

chrisdone / Duet

Licence: other
A tiny language, a subset of Haskell aimed at aiding teachers teach Haskell

Programming Languages

haskell
3896 projects

Projects that are alternatives of or similar to Duet

Wswp
Code for the second edition Web Scraping with Python book by Packt Publications
Stars: ✭ 112 (-27.74%)
Mutual labels:  teaching
Vscode Deploy Reloaded
Recoded version of Visual Studio Code extension 'vs-deploy', which provides commands to deploy files to one or more destinations.
Stars: ✭ 129 (-16.77%)
Mutual labels:  compilers
Learnquery
Learn JavaScript fundamentals by building your own jQuery equivalent library
Stars: ✭ 136 (-12.26%)
Mutual labels:  teaching
Build Essential
Development repository for build-essential Chef Cookbook
Stars: ✭ 118 (-23.87%)
Mutual labels:  compilers
Simple Java Text Editor
📝 PHNotepad is a simple Java text/code editor (notepad) written in Java. It has also nice features such as Search tool, Find/Replace text/code, Auto completion, Nice Image Buttons for better UX, etc.
Stars: ✭ 128 (-17.42%)
Mutual labels:  teaching
Simple Java Calculator
🔢 Simple calculator written in Java with Eclipse. This calculator is simple with an easy code to help novices learn how to operate a calculator.
Stars: ✭ 130 (-16.13%)
Mutual labels:  teaching
Dataformsjs
🌟 DataFormsJS 🌟 A minimal JavaScript Framework and standalone React and Web Components for rapid development of high quality websites and single page applications.
Stars: ✭ 95 (-38.71%)
Mutual labels:  compilers
Rtutor
Creating interactive R Problem Sets. Automatic hints and solution checks. (Shiny or RStudio)
Stars: ✭ 141 (-9.03%)
Mutual labels:  teaching
Es6console
🔮 Play with ECMAScript compilers
Stars: ✭ 128 (-17.42%)
Mutual labels:  compilers
Journalism Syllabi
Computer-Assisted Reporting and Data Journalism Syllabuses, compiled by Dan Nguyen
Stars: ✭ 136 (-12.26%)
Mutual labels:  teaching
One
OneLang: The One System Programming Language. (release as soon)
Stars: ✭ 120 (-22.58%)
Mutual labels:  compilers
Gllvm
Whole Program LLVM: wllvm ported to go
Stars: ✭ 126 (-18.71%)
Mutual labels:  compilers
Public
Public documents for the Master of Data Science program at the University of British Columbia
Stars: ✭ 133 (-14.19%)
Mutual labels:  teaching
Ocamlverse.github.io
Documentation of everything relevant in the OCaml world
Stars: ✭ 117 (-24.52%)
Mutual labels:  compilers
You Dont Know X
🙈 curated list of inspiring resources which show you don't know that much about something you thought you knew.
Stars: ✭ 139 (-10.32%)
Mutual labels:  compilers
Research And Coding
研究资源列表 A curated list of research resources
Stars: ✭ 100 (-35.48%)
Mutual labels:  teaching
Stats337
Readings in applied data science
Stars: ✭ 1,625 (+948.39%)
Mutual labels:  teaching
Py Rse
Research Software Engineering with Python course material
Stars: ✭ 145 (-6.45%)
Mutual labels:  teaching
Yrssf
一个分布式(p2p)云教学/云课堂/直播平台系统CMS,睿易派的开源替代品
Stars: ✭ 141 (-9.03%)
Mutual labels:  teaching
Openolat
Learning Management System OpenOlat
Stars: ✭ 135 (-12.9%)
Mutual labels:  teaching

Duet

A tiny language, a subset of Haskell (with type classes) aimed at aiding teachers teach Haskell

Run

Running code in Duet literally performs one substitution step at time. For example, evaluating (\x -> x + 5) (2 * 3), we get:

$ duet run demo.hs
(\x -> x + 5) (2 * 3)
(2 * 3) + 5
6 + 5
11

Note that this demonstrates basic argument application and non-strictness.

Docker run

Run with the docker distribution, to easily run on any platform:

$ docker run -it -v $(pwd):/w -w /w chrisdone/duet run foo.hs

(This should work on Linux, OS X or Windows PowerShell.)

The image is about 11MB, so it's quick to download.

Differences from Haskell

See also the next section for a complete example using all the available syntax.

  • Duet is non-strict, but is not lazy. There is no sharing and no thunks.
  • No module or import module system whatsoever.
  • No let syntax, no parameters in definitions e.g. f x = .. you must use a lambda. Representing let in the stepper presents a design challenge not currently met.
  • Kinds * are written Type: e.g. class Functor (f :: Type -> Type).
  • Kind inference is not implemented, so if you want a kind other than Type (aka * in Haskell), you have to put a kind signature on the type variable.
  • Indentation is stricter, a case's alts must be at a column larger than the case.
  • Duet does not have seq, but it does have bang patterns in cases. case x of !x -> .. is a perfectly legitimate way to force a value.
  • Infix operators are stricter: an infix operator must have spaces around it. You cannot have more than one operator without parentheses, therefore operator precedence does not come into play in Duet (this is intentional). This also permits you to write -5 without worrying about where it rests.
  • Superclasses are not supported.
  • Operator definitions are not supported.
  • There is only Integer and Rational number types: they are written as 1 or 1.0.
  • Any _ or _foo means "hole" and the interpreter does not touch them, it continues performing rewrites without caring. This is good for teaching.
  • There is no standard Prelude. The only defined base types are:
    • String
    • Char
    • Integer
    • Rational
    • Bool
  • You don't need a Show instance to inspect values; the interpreter shows them as they are, including lambdas.

View examples/syntax-buffet.hs for an example featuring all the syntax supported in Duet.

Print built-in types and classes

To print all types (primitive or otherwise), run:

$ duet types

Example output:

data Bool
  = True
  | False
data String
data Integer
data Rational

For classes and the instances of each class:

$ duet classes

Example output:

class Num a where
  plus :: forall a. (a -> a -> a)
  times :: forall a. (a -> a -> a)
instance Num Rational
instance Num Integer

class Neg a where
  negate :: forall a. (a -> a -> a)
  subtract :: forall a. (a -> a -> a)
  abs :: forall a. (a -> a)
instance Neg Rational
instance Neg Integer

class Fractional a where
  divide :: forall a. (a -> a -> a)
  recip :: forall a. (a -> a)
instance Fractional Rational

class Monoid a where
  append :: forall a. (a -> a -> a)
  empty :: forall a. a
instance Monoid String

class Slice a where
  drop :: forall a. (Integer -> a -> a)
  take :: forall a. (Integer -> a -> a)
instance Slice String

String operations

Strings are provided as packed opaque literals. You can unpack them via the Slice class:

class Slice a where
  drop :: Integer -> a -> a
  take :: Integer -> a -> a

You can append strings using the Monoid class:

class Monoid a where
  append :: a -> a -> a
  empty :: a

The String type is an instance of these classes.

main = append (take 2 (drop 7 "Hello, World!")) "!"

Evaluates strictly because it's a primop:

append (take 2 (drop 7 "Hello, World!")) "!"
append (take 2 "World!") "!"
append "Wo" "!"
"Wo!"

You can use this type and operations to teach parsers.

I/O

Basic terminal input/output is supported.

For example,

$ duet run examples/terminal.hs --hide-steps
Please enter your name:
Chris
Hello, Chris

And with steps:

$ duet run examples/terminal.hs
PutStrLn "Please enter your name: " (GetLine (\line -> PutStrLn (append "Hello, " line) (Pure 0)))
Please enter your name:
GetLine (\line -> PutStrLn (append "Hello, " line) (Pure 0))
Chris
(\line -> PutStrLn (append "Hello, " line) (Pure 0)) "Chris"
PutStrLn (append "Hello, " "Chris") (Pure 0)
Hello, Chris
Pure 0

How does this work? Whenever the following code is seen in the stepper:

PutStrLn "Please enter your name: " <next>

The string is printed to stdout with putStrLn, and the next expression is stepped next.

Whenever the following code is seen:

GetLine (\line -> <next>)

The stepper runs getLine and feeds the resulting string into the stepper as:

(\line -> <next>) "The line"

This enables one to write an example program like this:

data Terminal a
 = GetLine (String -> Terminal a)
 | PutStrLn String (Terminal a)
 | Pure a

main =
  PutStrLn
    "Please enter your name: "
    (GetLine (\line -> PutStrLn (append "Hello, " line) (Pure 0)))
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].