functional programming - How are all graphic and web libraries implemented in Haskell? -


i begin learn haskell. i've read pure functional language , in immutable. things input output, writing , reading databases cause mutability of state. know there thing in haskell called monads allow use imperative features in haskell io monad. i'm interesting imperative in haskell implemented of monads? on hackagedb there lot of packages allow work 3d-graphics, databases, parse html, write web servers , on , forth.

what general idea behind of this? allow haskell remain pure , simultaneously applicable writing this? hope make clear me. in advance!

i came understand these things using following analogy, i'll express javascript.

how can 1 express side-effecting computation?

1. function

that first thing comming mind:

var launchrockets = function () {   preparerockets( querydbforpreparationparameters() )   launchallpreparedrockets()   outputresults() } 

you can see effectful function calling bunch of other effectful functions, can produce unknown effects ensuing consequences.

2. instructions

another way express compose set of instructions describing effectful computations function later execute. (ever composed sql query?)

var launchrocketsinstructions = [   {     description: "prepare rockets",     parameters: {       description: "query db preparation parameters"     }   },   {     description: "launch prepared rockets"   },   {     description: "output results"   } ] 

so see in our second example? see immutable data tree describing computation instead of performing right away. there no side effects here, , composing data tree can surely use pure functions. , that's side effects in haskell. infrastructure language provides: monads, io, do-notation - these tools , abstractions simplifying task of composing single tree of instructions.

of course perform these instructions 1 have escape wild world of side-effects. in case of javascript execute(launchrocketsinstructions), in case of haskell runtime executing root of instruction tree produce function main of main module, becomes single entry point of program. thereby side effects in haskell occur outside of language scope, that's why it's pure.


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -