Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
118 changes: 118 additions & 0 deletions transformations.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ <h2>Comments</h2>
# This is a comment
</code></pre>

<pre><code class="gleam rust">
-- This is a comment
</code></pre>

</div>


Expand Down Expand Up @@ -204,6 +208,54 @@ <h2>Primitives</h2>

</code></pre>

<pre><code class="gleam haskell">
1: Int

1.1: Float

True: Bool

False: Bool

-- no char literal

"hello": String

-- multi-line String
"
This is useful(?) for holding JSON or other
content that has \"quotation marks\".
"



#(1,"c"): #(Int, String)

Some(123): Option(Int)

None: Option(a)

Ok(123): Result(Int, err)

Error("Problem!"): Result(String, a)

[1, 2, 3]: List(Int)

-- no Array in stdlib, JS thing see gleam_javascript



set.from_list([1, 2, 3]): Set(Int)



let x: Map(Int, Bool) = map.from_list([#(1 , True), #(2, False )])


-- Unit type
Nil: Nil
</code></pre>

</div>


Expand Down Expand Up @@ -245,6 +297,17 @@ <h2>Custom types</h2>

</code></pre>

<pre><code class="gleam rust">
type Status { Todo Doing Done }

Todo: Status

Doing: Status

Done: Status

</code></pre>

</div>

<p>Custom types can be polymorphic. <code>Maybe a</code> is an example:</p>
Expand Down Expand Up @@ -277,6 +340,15 @@ <h2>Custom types</h2>

</code></pre>

<pre><code class="gleam rust">
type Maybe(a) { Just(a) Nothing }

Just(123): Maybe(Int)

Nothing: Maybe(a)

</code></pre>

</div>


Expand Down Expand Up @@ -361,6 +433,37 @@ <h2>Records</h2>
}
</code></pre>

<pre><code class="gleam rust">
-- no anonymous records
type Point { -- nominal types for records
Point(x: Int, y: Int)
}
const point = Point(3, 4) -- create a record


point.x -- access field

list.map([ point, Point(x: 0, y: 0) ], fn(p) { p.x }) -- field access function

Point(..point, x: 6) -- update a field

Point(..point, -- update many fields
x: point.x + 1,
y: point.y + 1,
)

import gleam/int
fn dist(point) { -- no pattern matching on fields in function heads
let Point(x,y) = point
int.square_root(int.power(x, 2) + int.power(y, 2))
}

type Location { -- nominal types for records
Location(line: Int, column: Int)
}
</code></pre>


</div>


Expand Down Expand Up @@ -419,6 +522,17 @@ <h2>Functions</h2>
poly = \x -> 14
</code></pre>

<pre><code class="gleam rust">
addOne(x: Int) = x + 1


add(x: Int, y: Int) = x + y

add : Int -> Int -> Int
add = (+)
</code></pre>


</div>


Expand Down Expand Up @@ -964,6 +1078,10 @@ <h2>String interpolation</h2>
content: " Roc";
color: #fff;
}
.gleam::before {
content: " Gleam";
color: #fff;
}

pre {
float: left;
Expand Down