Examples-0.1.0: Haskell code examples
Copyright© Frank Jung 2023
LicenseGPL-3.0-only
Safe HaskellSafe-Inferred
LanguageHaskell2010

FuncType

Description

Defining data with functions

Code based off Haskell Cookbook by Yogesh Sajanikar, Chapter 3, Defining data with functions, page 83.

Some use-cases for using functions as types:

Generic programming and type classes

Functions as types are essential in generic programming, where algorithms are designed to operate seamlessly across various data types. Type classes, which organize types according to shared characteristics, frequently leverage functions as types to articulate these characteristics and facilitate generic operations.

Meta-programming and type-level computations

Meta-programming and type-level computations involve the use of functions as types. This concept allows programs to manipulate other programs or their representations. Additionally, functions as types facilitate type-level computations, where calculations are carried out during compile time using type information.

Synopsis

Types

newtype Func a b Source #

Type with a function value.

Constructors

Func (a -> b) 

Functions

apply :: Func a b -> a -> b Source #

Apply function to a value.

compose :: Func a b -> Func b c -> Func a c Source #

Compose two functions.