Values and common types
Core supplies the everyday types used in a NeoHaskell application: a mug’s name is Text, its requested quantity is Int, and its order identity is Uuid. This page is a lookup for those values and the operations that work on them. Syntax and expressions explains how to read function calls and pipelines; Types and records explains signatures and type parameters.
Types and their operations
Section titled “Types and their operations”A type being available through Core does not bring every operation from its module into scope. For example, Core re-exports Text, while converting its contents to uppercase uses a qualified import:
import Coreimport Text qualified
productLabel :: TextproductLabel = "ceramic mug" |> Text.toUpperproductLabel is "CERAMIC MUG". In Text.toUpper, the part before the dot names the imported module. It is different from order.quantity, where the dot reads a field from a record. Starter modules import Core explicitly, as above, and the generated language settings disable the implicit standard Prelude import.
Text becoming a quantity
Section titled “Text becoming a quantity”A checkout receives text, but an order needs a number. Text.toInt can recognize a number without deciding whether the shop should accept it. Its result is Maybe Int: Just carries a parsed number and Nothing means parsing failed.
"2"Text.toIntJust 2Quantity and stock checks"two"Text.toIntNothingNo number to checkEven a parsed negative number is still an Int. The order decision must separately require a positive quantity and sufficient stock. When reviewing an agent’s checkout code, inspect both the conversion failure and the business check; successful parsing only establishes the number’s representation.
These signatures show the direction and possible absence of each conversion. They describe library functions, rather than definitions to add to the application:
Text.toInt :: Text -> Maybe IntText.fromInt :: Int -> TextText.toFloat :: Text -> Maybe FloatText.fromFloat :: Float -> TextFor example, Text.toInt "2" gives Just 2, Text.toInt "two" gives Nothing, and Text.toInt "-2" gives Just (-2). In the other direction, Text.fromInt 2 gives "2". Decimal input such as Text.toFloat "12.5" gives Just 12.5; Text.fromFloat 12.5 gives "12.5". Quoted inputs here are example checkout values, not special keywords.
Text stores Unicode text. Use Char for a single character and Bytes for binary data. The Text module contains trimming, splitting, casing and byte conversions as well as number conversion.
Numbers and arithmetic
Section titled “Numbers and arithmetic”Int is a machine-sized signed whole number, suitable for quantities within its bounds. Int64 is explicitly 64-bit. NeoHaskell’s Float is backed by a double-precision floating-point number; its spelling does not mean a 32-bit value. Floating-point calculations can round, so an integer number of minor currency units is often a clearer choice for a mug’s price.
The operators distinguish integer division from floating-point division:
(//) :: Int -> Int -> Int(/) :: Float -> Float -> FloatmodBy :: Int -> Int -> IntremainderBy :: Int -> Int -> IntSeven mugs packed two per box give 7 // 2 == 3 full boxes. 7 / 2 == 3.5 calculates a floating-point quotient. Integer division truncates toward zero, so (-7) // 2 == -3. Both division operators require care around a zero divisor.
modBy and remainderBy take the divisor first. For a negative input they differ: modBy 4 (-5) == 3, while remainderBy 4 (-5) == -1. round chooses the nearest integer with ties going to the even integer: round 2.5 == 2 and round 3.5 == 4. Use floor, ceiling or truncate when the required direction is explicit. The Basics implementation defines these conventions.
Addition, subtraction and multiplication work on compatible numeric types. They do not implicitly mix an existing Int with a Float; fromIntegral can explicitly convert an integral value when a floating-point calculation needs it.
You may also encounter Natural Int. makeNatural returns Nothing for zero or a negative input and Just for a positive input. Treat that as this helper’s check, rather than a guarantee that every value of the exported Natural type was validated: its constructor and numeric instances are also available. Decimal is another type re-exported by Core; consult its module before choosing arithmetic or precision rules for a financial calculation.
Conditions and completion
Section titled “Conditions and completion”Bool has two values, True and False. Comparisons produce booleans, and &&, || and not combine or reverse them. For example, (2 :: Int) > 0 && True is True. Use a sum type when a shop status needs named alternatives such as awaiting payment, dispatched and cancelled; one boolean cannot explain those separate states.
Unit has one value, unit, also written (). It is useful when an operation completes without returning additional data. In Task error Unit, the task can still fail with error; Unit describes only the successful result. It does not mean the operation had no effects. Tasks and effects covers that distinction.
Order identities
Section titled “Order identities”Uuid represents an identifier rather than the text used to display it. Import Uuid qualified to parse, render or generate one:
import Uuid qualified
parseOrderId :: Text -> Maybe UuidparseOrderId input = Uuid.fromText inputparseOrderId "mug-1" gives Nothing. The text "00000000-0000-0000-0000-000000000000" parses as Just Uuid.nil, and Uuid.toText Uuid.nil renders that same text. The nil UUID is a fixed all-zero identifier, not a fresh order ID.
Uuid.generate returns a Task that generates a random UUID when run. Uuid.generateV5 instead derives an identifier deterministically from a namespace UUID and a text name. Repeating that pair produces the same identifier; it is not a secret. Parsing an ID checks its format, not whether an order exists or the caller may access it. The Uuid module defines these operations.
Finding related modules
Section titled “Finding related modules”Use the type in a signature to find the relevant family of operations. A qualified module import is still needed for operations such as Array.map or Task.yield.
| Types in application code | Qualified modules | Reference |
|---|---|---|
Array value, LinkedList value, Map key value |
Array, LinkedList, Map |
Arrays and maps |
Maybe value, Result error value |
Maybe, Result |
Maybe and Result |
Task error value |
Task |
Tasks and effects |
Json.Value |
Json |
JSON and schemas |
Unlike Text, Json.Value is not a type re-exported by Core; import Json qualified to name it. The Core export list is the exact index of available names. It also links the concurrency and implementation modules when a specific task calls for them.