Skip to content

Commit

Permalink
Doc.
Browse files Browse the repository at this point in the history
  • Loading branch information
skaller committed Nov 11, 2017
1 parent 9c99d0c commit 54bc207
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 4 deletions.
File renamed without changes.
3 changes: 2 additions & 1 deletion doc/tutorial/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ Contents:
.. toctree::
:maxdepth: 2

tutorial
hello
pythagoras

Indices and tables
==================
Expand Down
57 changes: 57 additions & 0 deletions doc/tutorial/pythagoras.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
Pythagoras
==========

The ancient Greek mathematician Pythagoras is famous for
the invariant of right angle triangles:

.. math::
h ^ 2 = w^ 2 + a^2
where `h` is the hypotenuse, `w` is the width of the base,
and `a` is the altitute.

We can calculate the hypotenuse in Felix like this:

.. code-block:: felix
fun hypot (w:double, a:double) : double =>
sqrt (w^2 + a^2)
;
println$ hypot (3.0, 4.0);
The type `double` is a standard double precision floating point real
number.

The `sqrt` function is in the library, and calculates the
square root of a double precision number.

The operator `^` denotes exponentiation, in this case
we are squaring, or muliplying the argument by itself twice,
the literal `2` is a value of type `int`, a type of small
integers.

Of course, the operator `+` is addition.

The `fun` binder is used here to define a function. Then we give
the function name we want to use, in this case `hypot`.

Then, in paranthesis we give a comma separated list of paramater
specifications. Each specification is the name of the parameter,
followed by its type.

It is good practice, but not required, to follow the parameters
with `:` and the return type of the function.

Then the `=>` symbol is used to begin the formula defining the function
in terms of the parameters.

The function can be used by applying it to an argument of the
correct type, in this case a pair, or tuple, of two numbers
of type `double`.

The `println` is then called on the application using
the application operator `$`.


7 changes: 4 additions & 3 deletions src/packages/fibres.fdoc
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,10 @@ open class Schannel
var ps = C_hack::cast[root::address]$ new v;
svc$ svc_swrite$ C_hack::cast[_schannel] chan, &ps;
}

proc write[T] (chan:oschannel[T], v:T) {
write (C_hack::cast[schannel[T]] chan, v);
}

//$ Multi Write an item to a bidirectional channel.
proc broadcast[T] (chan:schannel[T], v:T) {
Expand All @@ -316,9 +320,6 @@ open class Schannel
}

//$ Multi Write an item to an output channel.
proc write[T] (chan:oschannel[T], v:T) {
write (C_hack::cast[schannel[T]] chan, v);
}
proc broadcast[T] (chan:oschannel[T], v:T) {
broadcast (C_hack::cast[schannel[T]] chan, v);
}
Expand Down

0 comments on commit 54bc207

Please sign in to comment.