https://github.com/raineorshine/functional-solidity-language
A typed, functional language that targets the EVM.
https://github.com/raineorshine/functional-solidity-language
Last synced: 3 months ago
JSON representation
A typed, functional language that targets the EVM.
- Host: GitHub
- URL: https://github.com/raineorshine/functional-solidity-language
- Owner: raineorshine
- Created: 2017-01-18T20:20:47.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2017-01-20T15:35:07.000Z (over 8 years ago)
- Last Synced: 2025-03-18T08:02:33.567Z (3 months ago)
- Language: JavaScript
- Size: 16.6 KB
- Stars: 55
- Watchers: 9
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
This project is purely an imagining of what it would be like to write Ethereum smart contracts in a typed, functional programming language. It is not yet implemented beyond an extremely rough PEGJS parser and a demo code generator.
---
A simple smart contract:
```idris
MyContractState : State { balance : Uint }// declare a contract with a specific state type
MyContract : Contract MyContractState
MyContract = Contract// all contract methods take the contract state and return a new contract state
deposit : MyContractState -> MsgValue -> MyContractState
deposit state msgValue = MyContractState { balance = balance + msgValue }// dependent types can be imagined as a way to enforce constraints on effects
// e.g. in order to send ether you must prove that there is enough ether to send
send : MyContractState -> (amount : MsgValue) -> (to : Address) -> (MyContractState, EtherTransfer amount to balance)// descriptions of side effects are returned in a tuple with the new state.
// it is a purely functional language
send state amount to = (state, EtherTransfer amount to balance)
```Equivalent contract in Solidity:
* Yes, this was actually produced by the demo compiler with the above input.
* It doesn't do any type-checking and will break on almost any other input. Really it's just a proof-of-concept.```js
contract MyContract {
public uint balance;function deposit(msg.value) {
balance = balance + msg.value;
}function send(amount, to) {
if(!to.value(amount).call()) throw;
}
}
```## Usage
Generate solidity from the given sourcefile:
```sh
$ functional-solidity-language [sourcefile]
```Generate just the parsed AST:
```sh
$ functional-solidity-language --parse [sourcefile]
```## Status
- [x] Proof-of-concept parser
- [x] Proof-of-concept code generator
- [ ] 1st gen parser
- [ ] 1st gen code generator## License
ISC © [Raine Revere](http://raine.tech)