Maths - Category Theory - IO Monad

Languages such as Haskell require that all functions behave like mathematical functions. For instance:

These requirements would prevent the language from having input or output and all languages need these or there would not be any point to them.

Haskell allows input/output like this:

main = do
   putStrLn "type something"
	userinput <- getLine
	putStrLn $ "you typed:" ++ userinput 

This uses a way to isolate these 'non-pure' functions using monads.

The functions such as putStrLn and getLine do not return anything that would make them 'non-pure', instead they return IO, this is always the same for given inputs and therefore does not contravene the requirements. However IO contains a function to get the input say which can be called form outside the 'pure' code.

The 'do' construct in the program above links these functions together. This creates a separate 'program' within the Haskell code. haskell IO
This could be redrawn as an endo-function: haskell do loop

 


metadata block
see also:

http://www.mathreference.com/

Correspondence about this page

Book Shop - Further reading.

Where I can, I have put links to Amazon for books that are relevant to the subject, click on the appropriate country flag to get more details of the book or to buy it from them.

flag flag flag flag flag flag The Princeton Companion to Mathematics - This is a big book that attempts to give a wide overview of the whole of mathematics, inevitably there are many things missing, but it gives a good insight into the history, concepts, branches, theorems and wider perspective of mathematics. It is well written and, if you are interested in maths, this is the type of book where you can open a page at random and find something interesting to read. To some extent it can be used as a reference book, although it doesn't have tables of formula for trig functions and so on, but where it is most useful is when you want to read about various topics to find out which topics are interesting and relevant to you.

 

Terminology and Notation

Specific to this page here:

 

This site may have errors. Don't use for critical systems.

Copyright (c) 1998-2017 Martin John Baker - All rights reserved - privacy policy.