https://github.com/petroniuss/foolang
Interpreter for a small functional language!
https://github.com/petroniuss/foolang
haskell interpreter type-inference
Last synced: 8 days ago
JSON representation
Interpreter for a small functional language!
- Host: GitHub
- URL: https://github.com/petroniuss/foolang
- Owner: Petroniuss
- Created: 2020-09-06T20:51:36.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2020-09-29T09:15:40.000Z (over 4 years ago)
- Last Synced: 2025-03-24T09:25:18.424Z (3 months ago)
- Topics: haskell, interpreter, type-inference
- Language: Haskell
- Homepage:
- Size: 135 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: ChangeLog.md
Awesome Lists containing this project
README
# FooLang
Interpreter for a small ⚡functional language⚡.
## Demo

## Characteristics
- It's statically typed, but types are inferred rather than manually specifed.
- Haskell-like lambdas and function application:
- ```
let identity x = xlet lambdaId = (\x -> x)
let foo = 12 + (identity 1)
```- It uses Hindley–Milner type system for type inference and polymorhphic types(✔)
- `let id = (\x -> x)` - type of id: forall a => a -> a
- `let flip f x y = f y x` - type of f: forall a b c => (b -> a -> c) -> (a -> b -> c).
If you run that you will note that brackets are omitted, but since arrow is right-associative it's all the same.- Two base types:
- Int - as big as it needs to be,
- Bool - True or False.- Supports reccursion(✨):
```
let rec fib n =
if (n <= 0) then
0
else if (n == 1) then
1
else
(fib (n - 1)) + (fib (n - 2))
```- Interpreter supports few commands:
- `:type fibb` - checks type of given identifier (in this case `fibb`),
- `:browse` - prints list of defined functions with their respective types,
- `:quit` - quits shell (same as CTRL-D),
- `:load path` - loads module from a file,
- `:paste` - enter multline mode.For a code snippet look at [🔥🔥example](./foo-scripts/script.foo).
## Try it yourself
If you have stack (haskell build tool) installed on your machine just
clone the repo and enter `stack run`.You can also run `stack install` which will install the binaries in ~/usr/bin/.
Then to run shell, simply eneter `FooLang-exe`.