Skip to content

Latest commit

 

History

History
286 lines (184 loc) · 4.88 KB

prelude.md

File metadata and controls

286 lines (184 loc) · 4.88 KB

prelude

module Implements the most basic data types. Espcially those needed for built-in functionality and for the compiler. Will always be imported implicitly.

Any

extern Any value that exists.

Bool

enum Represents boolean values like True and False. Typically used for conditionals and flags.

Cases

Char

extern A single character of a string.

Cons

data Represents a non-empty List.

Properties

  • head - The first element
  • tail - The remaining list. @type List

Dict

extern Stores values for given String-keys. As dicts are immutable, all changing operations return new copies.

Properties

  • delete key - Creates a copy Dict, which includes no value for the given key. The current Dict stays at it is.
  • entries - A List of all entries as Pair.
  • get key - Returns Some value for a specific key or None.
  • keys - A List of all keys.
  • length - The count of all key-value-pairs.
  • set key, value - Creates a copy Dict, which includes the given key-value-pair. The current Dict stays at it is.
  • values - A List of all values.

False

data A constant to represent invalid conditions.

Float

extern A base type for floating point numbers like 13.37.

Function

extern A function that may be called.

Properties

  • arity - The minimum arity of the function. If it returns another function, the actual arity might be higher.

Int

extern A base type for non-fractional numbers like -1, 0, 1 and 2.

List

enum A list of arbiratry elements.

import lists

let myList = [1, 2, 3, 4]
lists.reduce { l, r => l + r }, 0, myList

Cases

Maybe

enum An uknown value. Might be an optional, the value itself or None.

Cases

Module

extern A module. Either from an import or by a module-declaration.

Never

enum An enum with no valid values. Allows empty, but valid type expressions.

Nil

data Marks the end of the list.

None

data

Optional

enum An optional value. Either some value or none.

Cases

Pair

data A pair of values.

Properties

  • key - The associated key.
  • value - The associated value.

Some

data

Properties

  • value

String

extern Represents text like "hello world".

Properties

  • append str - Allows to append another string.
  • length - The length of the string.

True

data A constant to represent valid conditions.

Void

data Represents a single value.

compose

func compose f, g, value

Composes two given functions. Calls the second function first and pipes the result into the second one.

const

func const value, _

Always returns the first argument.

debug

func debug message

Prints a debug message to stdout.

eager

func eager value

Eagerly evaluates a given value recursively. All members of lists, dictionaries and data structures will be evaluated.

identity

func identity value

Always returns the given argument.

if

func if condition, then, else

When the given condition evaluates to True, returns then. Otherwise false. Both, then and else are evaluted lazily.

if True, print "Succeeded", exit 1

pipe

func pipe functions, initial

Pipes a given value through a list of functions. The first function is applied to the value, the second to the result of the first, etc.

print

func print message

Prints a message to stdout.

unless

func unless condition, then

Only if a condition is False, the right side will be executed and returned. Otherwise Void.

when

func when condition, then

Only if a condition is True, the right side will be executed and returned. Otherwise Void.

with

func with value, body

Applies the given body to the given value. Mostly useful for readability, e.g. in destructings.

with True, Bool(True: { _ => }, False: { _ => })