Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Haskell
Wiki community
Recent changes
Random page
HaskellWiki
Search
Search
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
Denotative
(section)
Page
Discussion
English
Read
Edit
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
View history
General
What links here
Related changes
Special pages
Page information
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
== Being privately imperative == [https://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.144.2237&rep=rep1&type=pdf In 1994] researchers discovered a way to denotatively accommodate the imperative style by excluding the use of <i>externally visible</i> side-effects. For example: <blockquote> <haskell> type Graph = Array Vertex [Vertex] data Tree a = Node a [Tree a] dfs :: Graph -> [Vertex] -> [Tree Vertex] dfs g vs = runST ( newSTArray (bounds g) False >>= \ marks -> search marks vs ) where search :: STArray s Vertex Bool -> [Vertex] -> ST s [Tree Vertex] search marks [] = return [] search marks (v:vs) = readSTArray marks v >>= \ visited -> if visited then search marks vs else writeSTArray marks v True >> search marks (g!v) >>= \ ts -> search marks vs >>= \ us -> return ((Node v ts): us) </haskell> :<small>from Figure 2 (page 17 of 51) of [https://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.52.3656&rep=rep1&type=pdf State in Haskell]</small> </blockquote> Even though <code>dfs</code>'s local definition: <haskell> search :: STArray s Vertex Bool -> [Vertex] -> ST s [Tree Vertex] </haskell> uses mutability and sequencing, the use of <code>runST</code> keeps those imperative details confined to <code>dfs</code>, hence its denotative type: <haskell> dfs :: Graph -> [Vertex] -> [Tree Vertex] </haskell> Therefore to be denotative, a programming language only needs to avoid using side effects which are externally visible: namely those of I/O.
Summary:
Please note that all contributions to HaskellWiki are considered to be released under simple permissive license (see
HaskellWiki:Copyrights
for details). If you don't want your writing to be edited mercilessly and redistributed at will, then don't submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource.
DO NOT SUBMIT COPYRIGHTED WORK WITHOUT PERMISSION!
Cancel
Editing help
(opens in new window)
Toggle limited content width