haskell - What kind of data structure is a monad? -


i have half-competent understanding of monad (a parameterized type provides context useful computation building), why exists (so can things require context, io), how use (bind returned variables >>=), , rough understanding of fits in in category theory (a category guarantees homogeneity of contexts of functions)**.

what, however, monad in terms of underlying data structure? since related applicative functor (which seems list), guess ghc takes monad's contents , puts them linked list of sort, , passes them around throughout computation.

what going on underneath hood?

** feel free correct of if know better.

monad not data structure — it's property.

you can define class of data types have default values (like [] lists, 0 int, false bool , on). let's call class defaultable. postulate default integer 0 , prove type of integers defaultable. bool defaultable in same way.

another example tostringable class (show in haskell): type tostringable if there function string. int , bool tostringable, because can write functions

inttostring  :: int  -> string booltostring :: bool -> string 

(and lists of type [a] meaningfully tostringable if a tostringable)

likewise, type of lists monad: can define 2 operations (that obey laws) return , (>>=) , prove type of lists forms monad. , is: if can define 2 operations

return :: -> m (>>=)  :: m -> (a -> m b) -> m b 

for concrete m, m monad. monad class , classes remind interfaces in oop.

internally it's dictionaries passing.


Comments

Popular posts from this blog

how to insert data php javascript mysql with multiple array session 2 -

multithreading - Exception in Application constructor -

windows - CertCreateCertificateContext returns CRYPT_E_ASN1_BADTAG / 8009310b -