GithubHelp home page GithubHelp logo

egison-tutorial's Introduction

The Egison Tutorial

This is a repository for a tutorial program of Egison. Egison is a pattern-matching-oriented, purely functional programming langauge. Using Egison, we can represent intuitive patterns for non-free data types such as multisets, sets, graphs, and mathematical expressions.

For more information, please visit Egison website.

How to compile and run

% cabal install
% egison-tutorial
Egison Tutorial Version 4.0.0
Welcome to Egison Tutorial!
** Information **
We can use a "Tab" key to complete keywords on the interpreter.
If we type a "Tab" key after a closed parenthesis, the next closed parenthesis will be completed.
*****************
==============================
List of sections in the tutorial.
1: Arithmetic
2: Basics of functional programming
3: Basics of pattern matching
4: Pattern matching for multisets and sets
5: Symbolic computation
6: Differential geometry: tensor analysis
7: Differential geometry: differential forms
==============================
Choose a section to learn.
(1-7): 4
====================
We can describe pattern matching for multisets and sets.
We can change the interpretation of patterns by changing the matcher, the second argument of the matchAll expression).
The meaning of the cons pattern (::) is generalized to divide a collection into "an" element and the rest.

Examples:
  matchAll [1, 2, 3] as list integer with $x :: $xs -> (x, xs)
  matchAll [1, 2, 3] as multiset integer with $x :: $xs -> (x, xs)
  matchAll [1, 2, 3] as set integer with $x :: $xs -> (x, xs)
====================
> matchAll [1, 2, 3] as list integer with $x :: $xs -> (x, xs)
[(1, [2, 3])]

egison-tutorial's People

Contributors

dvberkel avatar egisatoshi avatar greymd avatar hatappo avatar kotapiku avatar mikulely avatar momohatt avatar sakas-- avatar timmyjose avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

egison-tutorial's Issues

Ambiguous occurrence 'optShowVersion'

Cabal raised error when I was building egison-tutorial-4.0.1 with egison-4.1.0 on haskell:8 docker container:

...
#5 682.3 Failed to build exe:egison-tutorial from egison-tutorial-4.0.1.
#5 682.3 Build log (
#5 682.3 /root/.cabal/logs/ghc-8.10.7/egison-tutorial-4.0.1-e-egison-tutorial-32bbd66ddf7ace983264a8c8fd3aa0a36c7835f7efc41de2c0131eaf79103b5c.log
#5 682.3 ):
#5 682.3 Configuring executable 'egison-tutorial' for egison-tutorial-4.0.1..
#5 682.3 Preprocessing executable 'egison-tutorial' for egison-tutorial-4.0.1..
#5 682.3 Building executable 'egison-tutorial' for egison-tutorial-4.0.1..
#5 682.3 [1 of 2] Compiling Paths_egison_tutorial ( dist/build/egison-tutorial/autogen/Paths_egison_tutorial.hs, dist/build/egison-tutorial/egison-tutorial-tmp/Paths_egison_tutorial.o )
#5 682.3 [2 of 2] Compiling Main             ( Main.hs, dist/build/egison-tutorial/egison-tutorial-tmp/Main.o )
#5 682.3
#5 682.3 Main.hs:43:22: error:
#5 682.3     Ambiguous occurrence ‘optShowVersion’
#5 682.3     It could refer to
#5 682.3        either ‘Language.Egison.optShowVersion’,
#5 682.3               imported from ‘Language.Egison’ at Main.hs:17:1-32
#5 682.3               (and originally defined in ‘Language.Egison.CmdOptions’)
#5 682.3            or ‘Main.optShowVersion’, defined at Main.hs:51:5
#5 682.3    |
#5 682.3 43 |             Options {optShowVersion = True} -> printVersionNumber
#5 682.3    |                      ^^^^^^^^^^^^^^
#5 682.3
#5 682.3 Main.hs:44:22: error:
#5 682.3     Ambiguous occurrence ‘optPrompt’
#5 682.3     It could refer to
#5 682.3        either ‘Language.Egison.optPrompt’,
#5 682.3               imported from ‘Language.Egison’ at Main.hs:17:1-32
#5 682.3               (and originally defined in ‘Language.Egison.CmdOptions’)
#5 682.3            or ‘Main.optPrompt’, defined at Main.hs:53:5
#5 682.3    |
#5 682.3 44 |             Options {optPrompt = prompt} -> do
#5 682.3    |                      ^^^^^^^^^
#5 682.3
#5 682.3 Main.hs:61:5: error:
#5 682.3     Ambiguous occurrence ‘optShowVersion’
#5 682.3     It could refer to
#5 682.3        either ‘Language.Egison.optShowVersion’,
#5 682.3               imported from ‘Language.Egison’ at Main.hs:17:1-32
#5 682.3               (and originally defined in ‘Language.Egison.CmdOptions’)
#5 682.3            or ‘Main.optShowVersion’, defined at Main.hs:51:5
#5 682.3    |
#5 682.3 61 |     optShowVersion = False,
#5 682.3    |     ^^^^^^^^^^^^^^
#5 682.3
#5 682.3 Main.hs:63:5: error:
#5 682.3     Ambiguous occurrence ‘optPrompt’
#5 682.3     It could refer to
#5 682.3        either ‘Language.Egison.optPrompt’,
#5 682.3               imported from ‘Language.Egison’ at Main.hs:17:1-32
#5 682.3               (and originally defined in ‘Language.Egison.CmdOptions’)
#5 682.3            or ‘Main.optPrompt’, defined at Main.hs:53:5
#5 682.3    |
#5 682.3 63 |     optPrompt = "> ",
#5 682.3    |     ^^^^^^^^^
#5 682.3
#5 682.3 Main.hs:72:28: error:
#5 682.3     Ambiguous occurrence ‘optShowVersion’
#5 682.3     It could refer to
#5 682.3        either ‘Language.Egison.optShowVersion’,
#5 682.3               imported from ‘Language.Egison’ at Main.hs:17:1-32
#5 682.3               (and originally defined in ‘Language.Egison.CmdOptions’)
#5 682.3            or ‘Main.optShowVersion’, defined at Main.hs:51:5
#5 682.3    |
#5 682.3 72 |     (NoArg (\opts -> opts {optShowVersion = True}))
#5 682.3    |                            ^^^^^^^^^^^^^^
#5 682.3
#5 682.3 Main.hs:78:36: error:
#5 682.3     Ambiguous occurrence ‘optPrompt’
#5 682.3     It could refer to
#5 682.3        either ‘Language.Egison.optPrompt’,
#5 682.3               imported from ‘Language.Egison’ at Main.hs:17:1-32
#5 682.3               (and originally defined in ‘Language.Egison.CmdOptions’)
#5 682.3            or ‘Main.optPrompt’, defined at Main.hs:53:5
#5 682.3    |
#5 682.3 78 |     (ReqArg (\prompt opts -> opts {optPrompt = prompt})
#5 682.3    |                                    ^^^^^^^^^
#5 682.3
#5 682.3 Main.hs:169:70: error:
#5 682.3     Not in scope: type constructor or class ‘EgisonTopExpr’
#5 682.3     |
#5 682.3 169 | getEgisonExprOrNewLine :: Options -> InputT IO (Either Bool (String, EgisonTopExpr))
#5 682.3     |                                                                      ^^^^^^^^^^^^^
#5 682.3
#5 682.3 Main.hs:172:81: error:
#5 682.3     Not in scope: type constructor or class ‘EgisonTopExpr’
#5 682.3     |
#5 682.3 172 | getEgisonExprOrNewLine' :: Options -> String -> InputT IO (Either Bool (String, EgisonTopExpr))
#5 682.3     |                                                                                 ^^^^^^^^^^^^^
#5 682.3
#5 682.3 Main.hs:175:35: error:
#5 682.3     Ambiguous occurrence ‘optPrompt’
#5 682.3     It could refer to
#5 682.3        either ‘Language.Egison.optPrompt’,
#5 682.3               imported from ‘Language.Egison’ at Main.hs:17:1-32
#5 682.3               (and originally defined in ‘Language.Egison.CmdOptions’)
#5 682.3            or ‘Main.optPrompt’, defined at Main.hs:53:5
#5 682.3     |
#5 682.3 175 |              "" -> getInputLine $ optPrompt opts
#5 682.3     |                                   ^^^^^^^^^
#5 682.3
#5 682.3 Main.hs:176:55: error:
#5 682.3     Ambiguous occurrence ‘optPrompt’
#5 682.3     It could refer to
#5 682.3        either ‘Language.Egison.optPrompt’,
#5 682.3               imported from ‘Language.Egison’ at Main.hs:17:1-32
#5 682.3               (and originally defined in ‘Language.Egison.CmdOptions’)
#5 682.3            or ‘Main.optPrompt’, defined at Main.hs:53:5
#5 682.3     |
#5 682.3 176 |              _  -> getInputLine $ replicate (length $ optPrompt opts) ' '
#5 682.3     |                                                       ^^^^^^^^^
#5 682.3 cabal: Failed to build exe:egison-tutorial from egison-tutorial-4.0.1. See the
#5 682.3 build log above for details.
...
FROM haskell:8
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
RUN cabal update && \
    cabal install \
    egison-4.1.0 \
    egison-tutorial
WORKDIR /docker
ENTRYPOINT ["egison"]

Cannot be built with Egison 3.10.0

$ cabal v2-build
Resolving dependencies...
Build profile: -w ghc-8.8.1 -O1
In order, the following will be built (use -v for more details):
 - egison-tutorial-3.9.3 (exe:egison-tutorial) (configuration changed)
Configuring executable 'egison-tutorial' for egison-tutorial-3.9.3..
Preprocessing executable 'egison-tutorial' for egison-tutorial-3.9.3..
Building executable 'egison-tutorial' for egison-tutorial-3.9.3..
[1 of 2] Compiling Paths_egison_tutorial ( /egison-tutorial/dist-newstyle/build/x86_64-linux/ghc-8.8.1/egison-tutorial-3.9.3/x/egison-tutorial/build/egison-tutorial/autogen/Paths_egison_tutorial.hs, /egison-tutorial/dist-newstyle/build/x86_64-linux/ghc-8.8.1/egison-tutorial-3.9.3/x/egison-tutorial/build/egison-tutorial/egison-tutorial-tmp/Paths_egison_tutorial.o ) [Optimisation flags changed]
[2 of 2] Compiling Main             ( Main.hs, /egison-tutorial/dist-newstyle/build/x86_64-linux/ghc-8.8.1/egison-tutorial-3.9.3/x/egison-tutorial/build/egison-tutorial/egison-tutorial-tmp/Main.o ) [Optimisation flags changed]

Main.hs:47:35: error:
    Not in scope: ‘ET.defaultOption’
    Module ‘Language.Egison.Types’ does not export ‘defaultOption’.
   |
47 |                 env <- initialEnv ET.defaultOption
   |                                   ^^^^^^^^^^^^^^^^

Main.hs:227:45: error:
    Not in scope: ‘ET.defaultOption’
    Module ‘Language.Egison.Types’ does not export ‘defaultOption’.
    |
227 |         result <- liftIO $ runEgisonTopExpr ET.defaultOption env topExpr
    |                                             ^^^^^^^^^^^^^^^^

I guess this is caused by egison/egison@304dfe8

Approximate value of π²/6

In this line of the tutorial, we calculate an approximate value of (/ (power pi 2) 6).

But we can't show the real value of (/ (power pi 2) 6) in Egison because pi is defined as a symbol π and because it seems that Egison doesn't have f.power currently.

Proposal: Therefore, how about adding a description how to calculate the real value? For example, we can calculate the value by (f./ (f.* f.pi f.pi) 6.0).

Ambiguous references when installing a tutorial with cabal

Hello, I just wanted to try Egison and install the tutorial. Online version of a tutorial doesn't seem to work for now:

sh: 1: egison-tutorial: not found

I tried to install egison-tutorial via Hackage on Ubuntu 18.04.3 LTS.:

 cabal install egison-tutorial

I was able to install egison itself, but not egison-tutorial app. When I am trying to install it, I see this output:

Failed to install egison-tutorial-3.7.14
Build log ( /home/grid/.cabal/logs/egison-tutorial-3.7.14.log ):
cabal: Entering directory '/tmp/cabal-tmp-30833/egison-tutorial-3.7.14'
Configuring egison-tutorial-3.7.14...
Building egison-tutorial-3.7.14...
Preprocessing executable 'egison-tutorial' for egison-tutorial-3.7.14...
[1 of 2] Compiling Paths_egison_tutorial ( dist/build/autogen/Paths_egison_tutorial.hs, dist/build/egison-tutorial/egison-tutorial-tmp/Paths_egison_tutorial.o )
[2 of 2] Compiling Main             ( Main.hs, dist/build/egison-tutorial/egison-tutorial-tmp/Main.o )

Main.hs:42:22: error:
    Ambiguous occurrence ‘optShowVersion’
    It could refer to either ‘Language.Egison.optShowVersion’,
                             imported from ‘Language.Egison’ at Main.hs:18:1-22
                             (and originally defined in ‘Language.Egison.Types’)
                          or ‘Main.optShowVersion’, defined at Main.hs:50:5

Main.hs:43:22: error:
    Ambiguous occurrence ‘optPrompt’
    It could refer to either ‘Language.Egison.optPrompt’,
                             imported from ‘Language.Egison’ at Main.hs:18:1-22
                             (and originally defined in ‘Language.Egison.Types’)
                          or ‘Main.optPrompt’, defined at Main.hs:52:5

Main.hs:60:5: error:
    Ambiguous occurrence ‘optShowVersion’
    It could refer to either ‘Language.Egison.optShowVersion’,
                             imported from ‘Language.Egison’ at Main.hs:18:1-22
                             (and originally defined in ‘Language.Egison.Types’)
                          or ‘Main.optShowVersion’, defined at Main.hs:50:5

Main.hs:62:5: error:
    Ambiguous occurrence ‘optPrompt’
    It could refer to either ‘Language.Egison.optPrompt’,
                             imported from ‘Language.Egison’ at Main.hs:18:1-22
                             (and originally defined in ‘Language.Egison.Types’)
                          or ‘Main.optPrompt’, defined at Main.hs:52:5

Main.hs:71:28: error:
    Ambiguous occurrence ‘optShowVersion’
    It could refer to either ‘Language.Egison.optShowVersion’,
                             imported from ‘Language.Egison’ at Main.hs:18:1-22
                             (and originally defined in ‘Language.Egison.Types’)
                          or ‘Main.optShowVersion’, defined at Main.hs:50:5

Main.hs:77:36: error:
    Ambiguous occurrence ‘optPrompt’
    It could refer to either ‘Language.Egison.optPrompt’,
                             imported from ‘Language.Egison’ at Main.hs:18:1-22
                             (and originally defined in ‘Language.Egison.Types’)
                          or ‘Main.optPrompt’, defined at Main.hs:52:5
cabal: Leaving directory '/tmp/cabal-tmp-30833/egison-tutorial-3.7.14'
cabal: Error: some packages failed to install:
egison-tutorial-3.7.14 failed during the building phase. The exception was:
ExitFailure 1

Matrix Example

This line :
["[| [| 1 2 |] [| 10 20 30 |] |]"
is supposed to be an example of a matrix. So, it should probably be
["[| [| 1 2 3 |] [| 10 20 30 |] |]".

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.