]> git.rmz.io Git - my-scheme.git/log
my-scheme.git
7 years agoIgnore spaces
Samir Benmendil [Sat, 13 Jan 2018 23:24:30 +0000 (23:24 +0000)]
Ignore spaces

We add the spaces `Parser` which returns nothing `()` and skips any
spaces.

`spaces` is already defined in Parsec, but does not do exactly what we
want, we can hide it from the import.

`skipMany a` matches 0 or more `a` and skips them.

`>>` is the **bind** operator. It may have completely different meanings
depending on the monad you use. In the Parser monad in means "try the
first parameter, then try the second with anything that is left", i.e.
"first skip all the spaces, then match the symbol".

7 years agoreadExpr function to check whether the input matches symbol
Samir Benmendil [Sat, 13 Jan 2018 23:05:55 +0000 (23:05 +0000)]
readExpr function to check whether the input matches symbol

`readExpr :: String -> String` defines `readExpr` to be a function
(`->`) from String to a String.

`readExpr input = ...` will assign anything on the rhs to the `readExpr`
function where `input` is mapped to the first parameter of that
function.

`case ... of` is a *filter*.

`parse a b c` is a function from Parsec where `a` is the parser it should
use, `b` is the name of the input which is used for error messages and
`c` is the String to parse.

`parse` returns an `Either` type whose `Left` constructor indicates an
error. If we get a `Right` value, we bind it to `val`, ignore it and
return the String "Found Value".

7 years agoDefine a parser for various symbols in Scheme
Samir Benmendil [Sat, 13 Jan 2018 22:41:38 +0000 (22:41 +0000)]
Define a parser for various symbols in Scheme

`symbol :: Parser Char` is probably not needed (?)

I don't understand where the `Parser` type comes from, I cannot see it
in the doc of `Text.ParserCombinators.Parsec`. It may be that
`ParserCombinators` is a compatibility layer and that `Parser` is
defined somewhere else.

`oneOf` is provided by Parsec.

7 years agoImport the Parsec library
Samir Benmendil [Sat, 13 Jan 2018 22:24:47 +0000 (22:24 +0000)]
Import the Parsec library

If we want to use the new library, it needs to be imported.

More info for the library can be found on GitHub.
https://github.com/haskell/parsec

7 years agoAdd Parsec dependencie
Samir Benmendil [Sat, 13 Jan 2018 22:22:28 +0000 (22:22 +0000)]
Add Parsec dependencie

This is a Parser module that will be used in the project.

`stack` makes it quite easy to add dependencies. Simply change the
`dependencies` list in `package.yaml` and run `stack build` again. Any
missing modules will be installed.

7 years agoReading input from stdin
Samir Benmendil [Sat, 13 Jan 2018 22:07:28 +0000 (22:07 +0000)]
Reading input from stdin

Introducing `getLine` which reads the next line from stdin.

7 years agoPrint the sum of two arguments
Samir Benmendil [Sat, 13 Jan 2018 22:06:26 +0000 (22:06 +0000)]
Print the sum of two arguments

`read`'s type is defined as `read :: (Read a) => String -> a`, i.e.
`read` takes as `String` and returns an `a` (number?). I don't know what
`=>` means. (`(Read a)` is an instance of class Read ?)

`show`'s type is a bit more complicated it seems as it has multiple
instances for various types of input. But in essence it takes a type and
returns a `String`.

7 years agoRead two arguments from commandline
Samir Benmendil [Sat, 13 Jan 2018 21:59:14 +0000 (21:59 +0000)]
Read two arguments from commandline

`!!` is the "list indexing" operator. It returns the value in the list
on the lhs at the index on the rhs.

`++` concatenates two lists.

A string is a list of chars.

7 years agoHello World with argument
Samir Benmendil [Sat, 13 Jan 2018 21:56:06 +0000 (21:56 +0000)]
Hello World with argument

This will simply print "Hello, " followed by the first argument from the
commandline.

Every Haskell program needs to have a main "action" in the Main module.
This is the entry point.

Files starting with `module <Foo>` will be part of the `Foo` module.

By convention modules are capitalized and definitions aren't.

`import System.Environment` provides `getArgs` to access cli arguments.

Haskell is strongly typed and types may be assigned with `::`. In this case
`main` is of type `IO ()` which is an IO action holding no information.
(more on that later hopefully, as I don't fully understand that.)

7 years agoNew project
Samir Benmendil [Sat, 13 Jan 2018 21:28:41 +0000 (21:28 +0000)]
New project

This project was generated by `stack new`. Some files are obviously not
in use yet, or simply wrong.

7 years agoRoot Commit
Samir Benmendil [Sat, 13 Jan 2018 20:45:07 +0000 (20:45 +0000)]
Root Commit