Skip to content

Instantly share code, notes, and snippets.

@smurphy8
Created March 23, 2023 23:42
Show Gist options
  • Save smurphy8/452c7a2f18647aeb0e408814b4fabf85 to your computer and use it in GitHub Desktop.
Save smurphy8/452c7a2f18647aeb0e408814b4fabf85 to your computer and use it in GitHub Desktop.

Introduction To Inferno

This document provides an overview of Inferno, a new hybrid scripting language based on languages like OCaml and Haskell. The language is highly restricted and is designed to allow developers to write code that can be evaluated to produce expected results.

Syntax

The language supports a variety of expressions that can be used to build complex programs. Here is an example of an expression:


Array.sum (Array.keepSomes [Some 3.0, None, Some 4.0])

This expression calculates the sum of an array after filtering out the None values. The expected result of this expression is 7.0, which is a double.

Expressions

Here are a few examples of expressions that can be evaluated using the language:

Array.sum

Array.sum (Array.keepSomes [Some 3.0, None, Some 4.0])

This expression calculates the sum of an array after filtering out the None values. The expected result of this expression is 7.0, which is a double.

Array.findFirstSome

Array.findFirstSome [None, Some 3.0, None, Some 4.0]

This expression finds the first element in an array that is not None. The expected result of this expression is a value that represents the found element.

Array.findLastSome


Array.findLastSome [None, Some 3.0, None, Some 4.0]

This expression finds the last element in an array that is not None. The expected result of this expression is a value that represents the found element.

Array.findFirstAndLastSome

Array.findFirstAndLastSome [None, Some 3.0, None, Some 4.0]

This expression finds both the first and last element in an array that is not None. The expected result of this expression is a tuple of two values, where each value represents the found element.

Option.map

Option.map (fun x -> x + 2) (Some 4.0)

This expression maps the given function to the value of the option, if it exists. The expected result of this expression is a value that represents the result of the mapping operation.

fromOption

fromOption 0 (Some 4.0)

This expression extracts the value of an option, or returns the default value if the option is None. The expected result of this expression is the value of the option or the default value, depending on the value of the option.

Operator "?"

(Some 4.0) ? 0

This expression returns the value of the option if it exists, or the given default value if the option is None. The expected result of this expression is the value of the option or the default value, depending on the value of the option.

Option.reduce

Option.reduce (fun d -> d + 2) 0.0 (Some 4.0)

This expression applies the given binary function to the elements of the option and returns the result. The expected result of this expression is a value that represents the result of the reduction operation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment