Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You use pattern matching for that: </p> <pre><code>advance :: DA -&gt; State -&gt; String -&gt; State advance (start, step, accept) fromState chars = .... </code></pre> <p>The <code>type</code> keyword just introduces <a href="http://en.wikibooks.org/wiki/Haskell/Type_declarations#type_for_making_type_synonyms" rel="nofollow noreferrer">type synonyms</a>. <code>DA</code> is just a synonym for a triple <code>(Integer, Integer -&gt; Char -&gt; Integer, Integer -&gt; Bool)</code>.</p> <p>Your naming is confusing. <code>delta</code> in the definition of <code>a</code> automaton is a state transition function, but in the definition of <code>toDA</code> function, a parameter named <code>delta</code> is a list. <code>ListDA</code> type is also just a synonym for a triple (a different one - of a state, a list of transitions, and a list of acceptable states).</p> <p>Here is how this can be coded, using recursion for loops:</p> <pre><code>advance (_, step, _) fromState chars = go fromState chars where go s [] = ... -- stop, and produce the state as the answer, -- when the input string (list of chars) has ended go s (c:cs) = -- if not, then let s2 = step s c -- make one step in go ....... -- and loop with new values </code></pre> <p>Notice we have no need here for the <code>start</code> or <code>accept</code> variables, so we can use the anonymous variable pattern <code>_</code> there. Also, <code>step</code> is a function of type <code>State -&gt; Char -&gt; State</code>, and that dictates the order of arguments used in the function call there. I.e. it accepts a state and a character, and produces a new state.</p> <p>If you don't know Haskell at all, you will likely benefit from reading (and working through) a good tutorial, <a href="http://learnyouahaskell.com/" rel="nofollow noreferrer">like this one</a>.</p> <p>Lastly, since you've said you're "not familiar with posting questions in a forum", please read about <a href="https://meta.stackexchange.com/a/5235/172601">accepting answers</a>, and <a href="https://meta.stackexchange.com/questions/7931/faq-for-stack-exchange-sites">FAQ</a> in general.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload