Cast

From Esolang
Jump to navigation Jump to search
Cast
Paradigm(s) Functional
Designed by Ashli Katt
Appeared in 2023
Computational class Unknown
Reference implementation [1]
File extension(s) .cast

About

Cast is an effectively-functional language based around casting datatypes between eachother.

Overview

A Cast program is a list of type definitions following this format:

TypeName<Subtype1, Subtype2, ...>
| Pattern -> Expression
| Pattern -> Expression
| Pattern -> Expression
...

A type can have any number of named sub-types. The names serve no purpose other than to document their expected type/purpose. The cast definitions below the type define how to cast one type to another.

A Pattern is either a variable (ie: a) or a destructure (ie: Pair<Pattern, Pattern>). Destructuring may be nested.

An Expression is either a variable reference (ie: a), a type construction (ie: Pair<A<>, b>), or a cast (ie: Expression -> Type) When casting, the first defined cast whose pattern matches the value will be used.

Input / Output

The program input and output are both a string. The input, say abc is first converted to a UTF-8 bitstring. 011000010110001001100011. Then it is converted into a value using these types: IO<input>, IO.1<next>, IO.0<next>, and IO.null<>. The example bitstring will become this: IO<IO.0<IO.1<IO.1<IO.0<...>>>>> The final IO.0 or IO.1 will contain a IO.null inside.

The program is begun with the call io_object -> Main -> IO. The reverse-process is used after the cast to return the output string.

Examples

Cat Program

Main<I> // Main stores one value.
| IO<I> -> Main<I> // IO places its data inside of Main.
| Main<I> -> IO<I> // Main transfers its data to IO.

Hello, world! program

Main
| IO<_> -> Main<>
| Main<> -> IO<IO.0<IO.1<IO.0<IO.0<IO.1<IO.0<IO.0<IO.0<IO.0<IO.1<IO.1<IO.0<IO.0<IO.1<IO.0<IO.1<
IO.0<IO.1<IO.1<IO.0<IO.1<IO.1<IO.0<IO.0<IO.0<IO.1<IO.1<IO.0<IO.1<IO.1<IO.0<IO.0<IO.0<IO.1<IO.1<
IO.0<IO.1<IO.1<IO.1<IO.1<IO.0<IO.0<IO.1<IO.0<IO.1<IO.1<IO.0<IO.0<IO.0<IO.0<IO.1<IO.0<IO.0<IO.0<
IO.0<IO.0<IO.0<IO.1<IO.1<IO.1<IO.0<IO.1<IO.1<IO.1<IO.0<IO.1<IO.1<IO.0<IO.1<IO.1<IO.1<IO.1<IO.0<
IO.1<IO.1<IO.1<IO.0<IO.0<IO.1<IO.0<IO.0<IO.1<IO.1<IO.0<IO.1<IO.1<IO.0<IO.0<IO.0<IO.1<IO.1<IO.0<
IO.0<IO.1<IO.0<IO.0<IO.0<IO.0<IO.1<IO.0<IO.0<IO.0<IO.0<IO.1<IO.null<>>>>>>>>>>>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>