<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body text="#000000" bgcolor="#FFFFFF">
<p>Hello, Benjamin. Nature of Haskell is to treat random values
under monad. Because generator returns different values on calls
with the same arguments. So, no way to "declare" such function as
"nondeterministic" function. Haskell is not good language for such
job. But there are more suitable languages for such kind of tasks.
If you prefer Haskell-like syntax, better will be to use ML family
language: modern F#, Ocaml or SML, where IO will not be involved -
all is under IO explicitly. But there is another good choice: <b>Mercury</b>.
It supports (sure, because it's declarative language and is based
on Prolog) special notations for computations:</p>
<ul>
<li>non-deterministic</li>
<li>deterministic</li>
<li>semi-deterministic</li>
<li><span style="color: rgb(0, 0, 0); font-family: "Times New
Roman"; font-size: medium; font-variant-ligatures:
normal; font-variant-caps: normal; font-weight: 400;
letter-spacing: normal; orphans: 2; text-align: left;
text-indent: 0px; text-transform: none; white-space: normal;
widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px;
text-decoration-style: initial; text-decoration-color:
initial;">multisolution</span></li>
</ul>
<p><span style="color: rgb(0, 0, 0); font-family: "Times New
Roman"; font-size: medium; font-variant-ligatures: normal;
font-variant-caps: normal; font-weight: 400; letter-spacing:
normal; orphans: 2; text-align: left; text-indent: 0px;
text-transform: none; white-space: normal; widows: 2;
word-spacing: 0px; -webkit-text-stroke-width: 0px;
text-decoration-style: initial; text-decoration-color: initial;">(see
more about these declarations here:
<a class="moz-txt-link-freetext" href="https://www.mercurylang.org/information/doc-release/mercury_ref/Determinism-categories.html#Determinism-categories">https://www.mercurylang.org/information/doc-release/mercury_ref/Determinism-categories.html#Determinism-categories</a>)</span><em
style="color: rgb(0, 0, 0); font-family: "Times New
Roman"; font-size: medium; font-variant-ligatures: normal;
font-variant-caps: normal; font-weight: 400; letter-spacing:
normal; orphans: 2; text-align: left; text-indent: 0px;
text-transform: none; white-space: normal; widows: 2;
word-spacing: 0px; -webkit-text-stroke-width: 0px;
text-decoration-style: initial; text-decoration-color: initial;"><br>
</em></p>
<span style="color: rgb(0, 0, 0); font-family: "Times New
Roman"; font-size: medium; font-variant-ligatures: normal;
font-variant-caps: normal; font-weight: 400; letter-spacing:
normal; orphans: 2; text-align: left; text-indent: 0px;
text-transform: none; white-space: normal; widows: 2;
word-spacing: 0px; -webkit-text-stroke-width: 0px;
text-decoration-style: initial; text-decoration-color: initial;">Also
it has type system close to Haskell: with type-families,
existential types, abstract types and so on, also it supports
functional programming totally...</span><span style="color: rgb(0,
0, 0); font-family: "Times New Roman"; font-size:
medium; font-variant-ligatures: normal; font-variant-caps: normal;
font-weight: 400; letter-spacing: normal; orphans: 2; text-align:
left; text-indent: 0px; text-transform: none; white-space: normal;
widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px;
text-decoration-style: initial; text-decoration-color: initial;"><br>
<br>
But, I'm sure, no problem to develop some DSL for Haskell which
will hide some details ;)<br>
<br>
===<br>
Best regards, Paul<br>
</span><em style="color: rgb(0, 0, 0); font-family: "Times New
Roman"; font-size: medium; font-variant-ligatures: normal;
font-variant-caps: normal; font-weight: 400; letter-spacing:
normal; orphans: 2; text-align: left; text-indent: 0px;
text-transform: none; white-space: normal; widows: 2;
word-spacing: 0px; -webkit-text-stroke-width: 0px;
text-decoration-style: initial; text-decoration-color: initial;"></em><br>
<br>
<div class="moz-cite-prefix">12.01.2018 18:26, Benjamin Redelings
пишет:<br>
</div>
<blockquote type="cite"
cite="mid:87c53da9-b197-94bb-d28a-580d5f69d6a7@gmail.com">Hi Oleg,
<br>
<br>
Thanks for the links! These are quite interesting.
<br>
<br>
1. Here is one situation that occurs in evolutionary biology where
I would want to have the full range of Haskell syntax available to
me. Consider a binary tree, where each tree node has an integer
name in [1..num_nodes tree]. The function (parent tree n) gives
the parent of node n and (root tree) gives the root node.
<br>
<br>
-- the expected value for a node is the value at its parent
<br>
mean node tree x | node == root tree = 0
<br>
| otherwise = x!!parent tree node
<br>
<br>
-- given a tree, simulate down the tree,
<br>
simulate_on_tree tree = let x = [sample $ normal (mean node
tree x) 1 | node <- [1..num_nodes tree]]
<br>
<br>
My understanding is that you cannot refer to the result of a
computation while performing a computation, as in:
<br>
<br>
do {x <- simulate_on_tree tree x}
<br>
<br>
Am I missing something?
<br>
<br>
<br>
On 01/11/2018 12:02 PM, Oleg Grenrus wrote:
<br>
<blockquote type="cite">(a) Non-determism is an effect, e.g.
simple list is non-determinism monad, for small discrete
distributions!
<br>
</blockquote>
<br>
2. Why would we want to consider non-determinism (in the sense of
returning an unpredictable value) as an effect? Certainly running
a non-deterministic function does not change global state like
modifying an IORef would. I'm also thinking of functions that are
(somehow) TRULY random, so they are not keeping a hidden state
around somewhere. I'm calling them "non-deterministic" instead of
"random" because I want to ignore (for the moment) the probability
distribution, and just say that the result is arbitrary.
<br>
<br>
3. Sampling from a normal distribution gives ONE value, and the
list of possible values is .... large :-) [i.e. it would include
all Double values.]
<br>
<br>
<br>
<blockquote type="cite">(b) Yes. We can write effectful code
"implicitly"
<br>
- You might look into *Automatically Escaping Monads*
<br>
- <a class="moz-txt-link-freetext" href="https://www.youtube.com/watch?v=wG8AErq6Bbo">https://www.youtube.com/watch?v=wG8AErq6Bbo</a>, slides:
<br>
<a class="moz-txt-link-freetext" href="http://benl.ouroborus.net/talks/2016-HIW-Escape.pdf">http://benl.ouroborus.net/talks/2016-HIW-Escape.pdf</a>
<br>
- <a class="moz-txt-link-freetext" href="http://disciple.ouroborus.net/">http://disciple.ouroborus.net/</a> or
<a class="moz-txt-link-freetext" href="https://github.com/DDCSF/ddc">https://github.com/DDCSF/ddc</a>
<br>
</blockquote>
4. Interesting - I like his approach to making the box / run
instructions implicit.
<br>
<br>
<blockquote type="cite">Interstingly, while searching for the
paper, I stumbled upon Oleg
<br>
Kiselyov's (not me) paper from
<br>
*Effects Without Monads: Non-determinism*, which is a different
approach.
<br>
Maybe that's what you are looking after
<br>
<a class="moz-txt-link-freetext" href="http://okmij.org/ftp/tagless-final/nondet-paper.pdf">http://okmij.org/ftp/tagless-final/nondet-paper.pdf</a>
<br>
</blockquote>
5. In this paper, it seems that non-determinism means returning
ALL possible outcomes. However, what I meant is arbitrarily
choosing ONE possible outcome. My terminology is probably being
imported from statistics - is there a different word I should use
here?
<br>
<br>
-BenRI
<br>
_______________________________________________
<br>
Haskell-Cafe mailing list
<br>
To (un)subscribe, modify options or view archives go to:
<br>
<a class="moz-txt-link-freetext" href="http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe">http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe</a>
<br>
Only members subscribed via the mailman list are allowed to post.<br>
</blockquote>
<br>
</body>
</html>