divs1210 / finkel

Haskell in S-expression

Home Page:https://finkel.readthedocs.io/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Finkel

CI status Documentation Codecov

Finkel is a statically typed, purely functional, and non-strict-by-default LISP flavored programming language.

Or in other words, Haskell in S-expression.

Features

  • Integration with existing Haskell modules.
  • Building Haskell-compatible Cabal packages.
  • Documentation generation with Haddock.
  • Lisp style macro system.
  • Tool executable, including interactive REPL.

Example

Sample code

;;;; File: fib.fnk

(:doc "Simple example module to show fibonacci number.

The compiled executable takes an integer argument from command line
input and print the fibonacci number of the argument.")

(defmodule Main
  (import
   (System.Environment [getArgs])))

(defn (:: main (IO ()))
  "The main entry point function."
  (>>= getArgs (. print fib read head)))

(defn (:: fib (-> Int Int))
  "Naive fibonacci function."
  [0] 0
  [1] 1
  [n] (+ (fib (- n 1))
         (fib (- n 2))))

Compiling an executable

$ finkel make -o fib fib.fnk
[1 of 1] Compiling Main             ( fib.fnk, fib.o )
Linking fib
$ ./fib 10
55

Running REPL

$ finkel repl
Hit `Ctrl-d' or type ,q to quit, type ,? for help.
> ,load fib.fnk
[1 of 1] Compiling Main             ( fib.fnk, interpreted )
; loaded fib.fnk
> ,info fib
fib :: Int -> Int       -- Defined at fib.fnk:16:11
> (map fib [1 .. 10])
[1,1,2,3,5,8,13,21,34,55]
> (System.Environment.withArgs ["10"] main)
55
> ,q

Further resources

See the documentation for more details.

Contributing

Contributions are welcome. Please see the CONTRIBUTING.md.

About

Haskell in S-expression

https://finkel.readthedocs.io/

License:BSD 3-Clause "New" or "Revised" License


Languages

Language:Haskell 97.4%Language:C 1.6%Language:Shell 0.5%Language:Nix 0.4%Language:Emacs Lisp 0.1%Language:Roff 0.0%