

GitHub - eeue56/derw: An Elm-inspired language that transpiles to TypeScript
source link: https://github.com/eeue56/derw
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

An Elm-inspired language that transpiles to TypeScript
Usage
You can run the derw compiler via npx. You must provide files via --files
.
npx @eeue56/derw Compiles Derw code Provide entry files via --files --files [string...]: Filenames to be given --target ts | js | derw: Target either TS or JS output --output string: Output directory name --verify : Run typescript compiler on generated files to ensure valid output --debug : Show a parsed object tree --only string: Only show a particular object --run : Should be run via ts-node/node --format : Format the files given in-place -h, --help : This help text
Example
You can find a bunch of examples in examples, along with the Typescript they generate. But the general gist is: Elm-compatible syntax where possible.
type Result a b = Err { error: a } | Ok { value: b } asIs : Result a b -> Result a b asIs result = case result of Err { error } -> Err { error } Ok { value } -> Ok { value }
Roadmap
0.0.1 alpha
- Arrays
[ ]
,[ 1, 2, 3 ]
,[ [ 1, 2, 3 ], [ 3, 2, 1 ] ]
- Booleans
true
,false
- Boolean equality
1 < 2
,1 <= 2
,1 == 2
,1 != 2
,1 > 2
,1 >= 2
- Boolean operations
true && false
,not true
,true || false
- Strings
""
,"hello world"
- Format strings
``
,`Hello ${name}`
- Numbers
-1
,0
,1
,-1.1
,1.1
- Addition
1 + 2
,"Hello" + name
- Subtraction
2 - 1
- Multiplication
2 * 1
- Division
2 / 1
- Pipe
[1, 2, 3] |> List.fold add
,List.fold add <| [1, 2, 3]
- Compose
>>
,<<
- Constants
hello = "hello world"
- Function definitions
- Lists
[ 1, 2, 3 ]
,[ "hello", "world" ]
- List ranges
[ 1..5 ]
,[ start..end ]
add : number -> number -> number add x y = x + y
- Function calls
three = add 1 2
- Module references
three = List.map identity [ 1, 2, 3 ]
- Union types
type Result a b = Err { error: a } | Ok { value: b }
- Type variables
type Thing a = Thing a
- Type aliases
type User = { name: string }
- Object literals
user: User user = { name: string }
- Imports
import List import Result exposing (map)
- Exports
exposing (map)
- Let statements
sayHiTo : User -> string sayHiTo user = let name = user.name in "Hello " + name sayHelloTo : User -> string sayHelloTo user = let getName: User -> string getName user = user.name in "Hello" + getName user
- If statements
type Animal = Animal { age: number } sayHiTo : Animal -> string sayHiTo animal = if animal.age == 1 of "Hello little one!" else "You're old"
- Case..of
type Animal = Dog | Cat sayHiTo : Animal -> string sayHiTo animal = case animal of Dog -> "Hi dog!" Cat -> "Hi cat!"
- Destructing in case..of
type User = User { name: string } sayHiTo : User -> string sayHiTo user = case user of User { name } -> "Hi " + name + !"
- List destructing
sayHiTo : List number -> string sayHiTo xs = case xs of [] -> "Empty" x::ys -> "Hello " + x + (sayHiTo ys)
- Constructing union types
type User = User { name: string } noah = User { name: "Noah" }
- lambdas
\x -> x + 1
,\x y -> x + y
- Typescript output
- Javscript output
- Module resolution
- Type checking
- Syntax highlighting for editors
1.0.0
- An automatic formatter with no options
- A standard library
- Support for Coed
- Testing support via Bach
- Benchmarking support via Mainc
Divergence from Elm
- All top level consts or functions must have type definitions
- Format strings ``
- No need for module names in the module file itself. Use
exposing
instead
Editor language support
Currently VSCode syntax highlighting is supported by this extension: https://github.com/eeue56/derw-syntax. It is not on the marketplace because Microsoft account creation was down when I tried.
Instead, you can do:
git clone https://github.com/eeue56/derw-syntax
cp -r derw-syntax ~/.vscode/extensions/derw-syntax-0.0.1
derw which means oak. Oak is one of the native trees in Wales, famous for it's long life, tall stature, and hard, good quality wood. An English speaker might pronounce it as "deh-ru".
Recommend
-
118
-
6
Cowgol 2.0 What? Cowgol is an experimental, Ada-inspired language for very small systems (6502, Z80, etc). It's different because it's intended to be self-hosted on these devices: the end goal is to be able to rebuild the en...
-
13
Jelly Jelly is a golfing language inspired by J. Documentation Quickstart The Jelly interpreter requires Python 3. To download, install, and use Jelly, proceed as follows. $ git cl...
-
7
Sonic Sonic programming language: Heavily inspired by Swift, but compiles to C so you can use it anywhere. Brought to you by Chris Hulbert and An...
-
5
PreludeThis post will talk about why I’ve decided to make a new typed ML language based on the TypeScript ecosystem. It’s very opinion based, so you might not agree with all I write, but that’s okay. The language is not ready for gen...
-
5
Derw, a friendly ML-like language for the web, status: January 2022, part 2In the second half of this month, I give my thoughts on new languages in the same space as Derw, configurability and my workflow. Improvements made...
-
7
All branches will diverge from the stem: from Elm to DerwNoah9 hr agoForgiv...
-
12
Table of contents fp programming language fp is a programming language heavily inspired by the language John Backus described in his 1977 Turing Award lecture. The paper can be found
-
9
-
6
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK