Derw is currently in a usable place, but there's a lot more planned. This page documents the current features, along with some ideas I have yet to implement.
Arrays [ ]
, [ 1, 2, 3 ]
, [ [ 1, 2, 3 ], [ 3, 2, 1 ] ]
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
Pipe [1, 2, 3] |> List.fold add
, List.fold add <| [1, 2, 3]
Constants hello = "hello world"
Lists [ 1, 2, 3 ]
, [ "hello", "world" ]
List ranges [ 1..5 ]
, [ start..end ]
Copy add : number -> number -> number
add x y = x + y
Module references
Copy three = List . map identity [ 1 , 2 , 3 ]
Union types
Copy type Result a b
= Err { error: a }
| Ok { value: b }
Type variables
Copy type Thing a = Thing a
Type aliases
Copy type alias User =
{ name: string }
Object literals
Copy user : User
user = { name : "Noah" }
Object literals updates
Copy user : User
user = { ... noah , name : "Noah" }
Imports
Copy import List
import Result exposing ( map )
import something as banana
Let statements
Copy 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
Copy type Animal = Animal { age: number }
sayHiTo : Animal -> string
sayHiTo animal =
if animal . age == 1 of
"Hello little one!"
else
"You're old"
Case..of
Copy type Animal = Dog | Cat
sayHiTo : Animal -> string
sayHiTo animal =
case animal of
Dog -> "Hi dog!"
Cat -> "Hi cat!"
Destructing in case..of
Copy type User = User { name: string }
sayHiTo : User -> string
sayHiTo user =
case user of
User { name } -> "Hi " + name + ! "
defaults in case..of
Copy sayHiTo : string -> string
sayHiTo name =
case name of
"Noah" -> "Hi " + name + ! "
default: " I don 't know you"
List destructing
Copy sum : List number -> number
sum xs =
case xs of
[] -> 0
y :: ys :: [] -> y + ys
z :: zs -> z + sum zs
default -> 0
List destructing with string values
Copy sum : List string -> number
sum xs =
case xs of
[] -> 0
"1" :: ys :: [] -> 1 + 2
"2" :: zs -> 2 + sum zs
default -> 0
List destructing with union types values
Copy sum : List (Maybe number) -> number
sum xs =
case xs of
[] -> 0
Just { value } :: rest -> value + sum rest
Nothing :: rest -> sum rest
default -> 0
Constructing union types
Copy type User = User { name: string }
noah = User { name : "Noah" }
Accessors
Copy type alias User = { name: string }
names = List . map . name [ { name : "Noah" } , { name : "Dave" } ]
Nested accessors
Copy type alias Group = { person: { name: string } }
names = List . map . person . name [ { person : { name : "Noah" } } , { person : { name : "Dave" } } ]
Errors on type name collison
Copy The name `Person` has been used for different things.
8 - 10:
```
type Person =
Person { name: string }
```
11 - 14:
```
type alias Person = {
name: string
}
```
Errors on function name collison
Copy The name `isTrue` has been used for different things.
0 - 3:
```
isTrue: boolean -> boolean
isTrue x =
x == true
```
4 - 7:
```
isTrue: boolean -> boolean
isTrue x =
x != true
```
Some form of basic type errors
Copy Failed to parse examples/errors/mismatching_types.derw due to:
Error on lines 0 - 3
Expected `boolean` but got `number` in the body of the function:
```
isTrue: boolean -> boolean
isTrue x =
1 + 2
```
Error on lines 4 - 7
Expected `List string` but got `List number` :
```
names: List string
names =
[1..2]
```
lambdas \x -> x + 1
, \x y -> x + y
Detect if types exist in current namespace
Syntax highlighting for editors
Collision detection for names in a module
Importing of Derw files
Copy import " . /other"
import " . /something" as banana
import " . /another" exposing ( isTrue , isFalse )
import " . / Maybe " as Maybe exposing ( Maybe )
Errors when failing to find relative import
Copy Warning! Failed to find `examples/derw_imports/banana` as either derw, ts or js
Single line comments
Copy -- hello
isTrue : boolean -> boolean
isTrue x =
x
Single line comments in function or const bodies
Copy isTrue : boolean -> boolean
isTrue x =
-- hello
x
Multiline comments
Copy {-
hello
world
-}
isTrue : boolean -> boolean
isTrue x =
x
Function arguments
Copy map : (a -> b) -> a -> b
map fn value =
fn value
Globals
Globals can be accessed through the globalThis
module which is imported into every namespace. E.g globalThis.console.log
Constant if statements
Copy name : string
name =
if 1 == 1 then
"Noah"
else
"James"
Constant case statements
Copy name : string
name =
case person of
"n" -> "Noah"
"j" -> "James"
default -> "Other"
List prepend
Copy numbers : List number
numbers =
1 :: [ 2 , 3 ]
1.0.0
An automatic formatter with no options
Testing support via Bach
Write a file with _test
as an extension (e.g List_test.derw
).
Copy import Test exposing ( equals )
testMath : boolean -> void
testMath a? =
equals 1 1
Compile it, then run bach via npx @eeue56/bach
Benchmarking support via Mainc
Package testing
Copy # inside a package directory
derw test
Install a package
Copy derw install --name derw-lang/stdlib --version main
An info command to find out stats about modules
Bundling
Copy derw bundle --entry src/Main.derw --output dist/index.js --watch --quiet
English output
Copy derw compile --target english
Template generation
Copy derw template --path src/Main.derw --template web
Do notation
Copy sayHi : string -> void
sayHi name =
do
globalThis . console . log "Hello" name
return
undefined
2.0.0
Type checking with interop with TypeScript
Derw compiler is written in Derw