Overview
TheIHP.Prelude module is the foundation of every IHP application, providing a curated set of commonly-used functions and types. It re-exports functionality from multiple libraries and adds IHP-specific utilities.
This prelude is automatically imported in:
IHP.ControllerPrelude(for controllers)IHP.ViewPrelude(for views)IHP.RouterPrelude(for routing)IHP.MailPrelude(for mail)
Core Exports
Text Operations
IHP usesText as the primary string type instead of String.
Convert any showable value to Text.
Alias for
show. Converts any showable value to Text.Generic string conversion function from
Data.String.Conversions.Concatenation operator, works with Text, lists, and other semigroups.
Safe List Functions
IHP provides safe alternatives to Prelude’s partial list functions that returnMaybe instead of throwing errors.
Safely get the first element of a list.
Safely get the last element of a list.
Safely get all elements except the first.
Safely get all elements except the last.
File System Paths
Cross-platform file path type. Use this instead of
String or Text for file paths.Convert Text to a file system path using UTF-8 encoding.
Convert a file system path back to Text.
Control Flow
Conditionally execute an action.
Conditionally execute an action when condition is False.
Map a monadic action over a traversable structure.
Like
mapM but with arguments flipped.Model Support
Re-exported fromIHP.ModelSupport for database operations.
Insert a new record into the database.
Update an existing record in the database.
Delete a record from the database.
Time Operations
Re-exported fromData.Time.* modules.
Absolute time type from
Data.Time.Clock.Get the current time.
Calendar day type from
Data.Time.Calendar.Local time type (no timezone) from
Data.Time.LocalTime.String Interpolation
String interpolation quasi-quoter.
Exception Handling
Throw a synchronous exception.
Throw an exception in IO.
Catch exceptions.
Concurrency
Run an IO action asynchronously from
Control.Concurrent.Async.Wait for an async action to complete.
Type-Level Programming
Proxy type for type-level programming.
Constraint for type-level strings.
Get the value of a type-level symbol.
Module Imports
The prelude re-exports from these modules:CorePrelude- Base functionalityData.Text- Text operationsData.Text.IO- Text I/O operationsIHP.HaskellSupport- IHP utilitiesIHP.ModelSupport- Database operationsIHP.NameSupport- Naming conventionsData.Time.*- Time operationsControl.Monad- Monadic operationsData.String.Conversions- String conversionsGHC.Records- Record field accessGHC.OverloadedLabels- Label syntax (#fieldName)Control.Exception.Safe- Safe exception handlingControl.Concurrent.Async- Asynchronous operations