Jaskell Shell

Jaskell Shell is an interactive command line interpreter for Jaskell. It is handy for experimenting simple jaskell expression or java statement real quick.

Run Jaskell Shell

In order to use Jaskell Shell. You need to download Jaskell jar file. Make sure the jfuntuil.jar, jparsec.jar and jaskell.jar are all in classpath. Then run "java"

The shell will then show:

The version number may vary depending on the version you are running on.

The ">" character is a command prompt.

Play with Swing

Now assume we want to try "javax.swing.JOptionPane.showInputDialog()", we can type in:

Hit the "Enter" key twice to evaluate this expression. (This is because shell allows you to enter expression in multiple lines, the first "enter" key may just start another line of the expression.)

A swing dialog will be popped up by now. Enter "13" in the input box, hit "Enter", the "13" will be shown as the value of the expression in the shell.

Note, we use square brackets instead of parenthesis for java method. This can be understood as a reflection call where an array of objects is passed to each method.

The above code is straight-forward, but not handy enough. Suppose we need to run "showInputDialog", "showConfirmationDialog" etc repeatedly, we certainly don't want to keep typing in "javax.swing.JOptionPane" again and again.

In order to do this, we can give "javax.swing.JOptionPane" an alias, kinda like typedef in C:

When "Enter" key is hit twice, the value of the expression is shown after "=>". In this case, the expression value is the JOptionPane class.

Now, we can use the shell command "?" to look at all the static methods supported by this "dialog":

Since "?" is a shell command, not a jaskell function, we just need to hit "Enter" once. It then shows us all the static methods of JOptionPane.

In order to run "showMessageDialog", we type in:

A "hello world" message dialog will be popped up.

To simplify the syntax even more, we can:

The value of this expression is a function called "say". This function expects one parameter.

Now we can "say" a lot of things:

blah blah blah.

Threading for dummies

The following expression starts a thread that prints "hello world":

  • We use the Ruby style "" here.
  • The constructor of Thread is called with one Runnable object as argument.
  • This Runnable object is created with a lamda function.
  • "\" denotes a lamda function.
  • The names between "\" and "->" are function parameters. "_" denotes a parameter that's not used.
  • The expression after "-" is the function body.
  • The "implements" function is used to adapt the function to interface Runnable.
  • The "`" symbol is used to call a function in an infix syntax. "implements(a,b)" is equivalent to "a `implements b".
  • start[] calls the "Thread.start()" method.

We could use the prelude function "const" to simplify the expression so that it becomes:

  • "const x" creates a function that ignores its parameter and always returns "x". It is equivalent to "_->x".

As we have done already, we can simplify the println as:

In fact, println function is already defined, you can use it without defining it. We define "println" here primarily as a demo of how functions can be defined to make syntax simpler.

Using the same technique, we can define a "run" function that makes running task in thread easy:

Let's see how we can use the "run" function:

The last "say nice" would have blocked the shell if it were not running in a thread. But calling it with "run", the shell is not blocked.

There are of course many other uses. Any jaskell expression can be typed in this shell.

Shell commands and special variables.

To see what functions are available globally:

To see what functions are available in a certain namespace:

To get the value of the previously evaluated expression:

To define more than one names in one line:

To exit shell:

To get help of shell commands:

Powered by Atlassian Confluence