clod
Copyright(c) Fuzz Leonard 2025
LicenseMIT
Maintainercyborg@bionicfuzz.com
Stabilityexperimental
Safe HaskellNone
LanguageHaskell2010

Clod.Effects

Description

This module provides types and utilities for working with effects in Clod. It uses a traditional monad transformer stack rather than an algebraic effects system, prioritizing type inference and error reporting clarity.

The module re-exports the core functionality from Clod.Types to provide a clean interface for working with the ClodM monad stack.

Synopsis

Core effect types

type ClodM a = ReaderT ClodConfig (ExceptT ClodError IO) a Source #

The Clod monad

This monad stack combines:

  • Reader for dependency injection of ClodConfig
  • Error handling with ExceptT for ClodError
  • IO for filesystem, git, and other side effects

This replaces the previous effects-based approach with a simpler, more traditional monad stack.

data ClodError Source #

Errors that can occur during Clod operation

These represent the different categories of errors that can occur during file processing, allowing for specific error handling for each case.

Constructors

FileSystemError !FilePath !IOError

Error related to filesystem operations

ConfigError !String

Error related to configuration (e.g., invalid settings)

PatternError !String

Error related to pattern matching (e.g., invalid pattern)

CapabilityError !String

Error related to capability validation

DatabaseError !String

Error related to checksums database

ChecksumError !String

Error related to checksum calculation

Instances

Instances details
Generic ClodError Source # 
Instance details

Defined in Clod.Types

Show ClodError Source # 
Instance details

Defined in Clod.Types

Eq ClodError Source # 
Instance details

Defined in Clod.Types

type Rep ClodError Source # 
Instance details

Defined in Clod.Types

data ClodConfig Source #

Configuration for the clod program

Constructors

ClodConfig 

Fields

Instances

Instances details
Generic ClodConfig Source # 
Instance details

Defined in Clod.Types

Associated Types

type Rep ClodConfig 
Instance details

Defined in Clod.Types

Show ClodConfig Source # 
Instance details

Defined in Clod.Types

Eq ClodConfig Source # 
Instance details

Defined in Clod.Types

type Rep ClodConfig Source # 
Instance details

Defined in Clod.Types

Running effects

runClodM :: ClodConfig -> ClodM a -> IO (Either ClodError a) Source #

Run a ClodM computation, returning either an error or a result

Monadic operations

throwError :: MonadError e m => e -> m a #

Is used within a monadic computation to begin exception processing.

catchError :: MonadError e m => m a -> (e -> m a) -> m a #

A handler function to handle previous errors and return to normal execution. A common idiom is:

do { action1; action2; action3 } `catchError` handler

where the action functions can call throwError. Note that handler and the do-block must have the same return type.

liftIO :: MonadIO m => IO a -> m a #

Lift a computation from the IO monad. This allows us to run IO computations in any monadic stack, so long as it supports these kinds of operations (i.e. IO is the base monad for the stack).

Example

Expand
import Control.Monad.Trans.State -- from the "transformers" library

printState :: Show s => StateT s IO ()
printState = do
  state <- get
  liftIO $ print state

Had we omitted liftIO, we would have ended up with this error:

• Couldn't match type ‘IO’ with ‘StateT s IO’
 Expected type: StateT s IO ()
   Actual type: IO ()

The important part here is the mismatch between StateT s IO () and IO ().

Luckily, we know of a function that takes an IO a and returns an (m a): liftIO, enabling us to run the program and see the expected results:

> evalStateT printState "hello"
"hello"

> evalStateT printState 3
3

Reader operations

ask :: MonadReader r m => m r #

Retrieves the monad environment.

asks #

Arguments

:: MonadReader r m 
=> (r -> a)

The selector function to apply to the environment.

-> m a 

Retrieves a function of the current environment.

local #

Arguments

:: MonadReader r m 
=> (r -> r)

The function to modify the environment.

-> m a

Reader to run in the modified environment.

-> m a 

Executes a computation in a modified environment.