<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  </head>
  <body text="#000000" bgcolor="#FFFFFF">
    <p>That's because Applicative is now a superclass of Monad. See the
      rationale here:
      <a class="moz-txt-link-freetext" href="https://wiki.haskell.org/Functor-Applicative-Monad_Proposal">https://wiki.haskell.org/Functor-Applicative-Monad_Proposal</a></p>
    <p><br>
    </p>
    <div class="moz-cite-prefix">On 27/02/2019 10:56, Damien Mattei
      wrote:<br>
    </div>
    <blockquote type="cite"
cite="mid:CADEOaddgXrYLmyqAWsA-s_yRiz8GNddqBTbdV=7SU7avCwdqSQ@mail.gmail.com">
      <meta http-equiv="content-type" content="text/html; charset=UTF-8">
      <div dir="ltr">
        <div dir="ltr">
          <div dir="ltr">
            <div dir="ltr">
              <div class="gmail_default" style="font-size:large">i'm
                trying this example (see code below) from :</div>
              <div class="gmail_default" style="font-size:large"><a
                  href="http://learnyouahaskell.com/for-a-few-monads-more#making-monads"
                  moz-do-not-send="true">http://learnyouahaskell.com/for-a-few-monads-more#making-monads</a></div>
              <div class="gmail_default" style="font-size:large"><br>
              </div>
              <div class="gmail_default" style="font-size:large">when
                trying to compile this:</div>
              <div class="gmail_default" style="font-size:large"><br>
              </div>
              <div class="gmail_default" style="font-size:large">import
                Data.Ratio<br>
                <br>
                newtype Prob a = Prob { getProb :: [(a,Rational)] }
                deriving Show<br>
                <br>
                <br>
                instance Functor Prob where<br>
                    fmap f (Prob xs) = Prob $ map (\(x,p) -> (f x,p))
                xs<br>
                <br>
                    <br>
                thisSituation :: Prob (Prob Char)<br>
                thisSituation = Prob<br>
                    [( Prob [('a',1%2),('b',1%2)] , 1%4 )<br>
                    ,( Prob [('c',1%2),('d',1%2)] , 3%4)<br>
                    ]<br>
                <br>
                flatten :: Prob (Prob a) -> Prob a<br>
                flatten (Prob xs) = Prob $ concat $ map multAll xs<br>
                    where multAll (Prob innerxs,p) = map (\(x,r) ->
                (x,p*r)) innerxs   <br>
                <br>
                <br>
                instance Monad Prob where<br>
                  return x = Prob [(x,1%1)]<br>
                  m >>= f = flatten (fmap f m)<br>
                  fail _ = Prob []<br>
                <br>
                <br>
                <br>
                l1 = Prob [('a',2%3),('b',1%3)]<br>
                <br>
                multAllExt :: (Prob a, Rational) -> [(a, Rational)]<br>
                multAllExt (Prob innerxs,p) = map (\(x,r) -> (x,p*r))
                innerxs<br>
                <br>
                --Main> :type multAllExt<br>
                --multAllExt :: (Prob a, Rational) -> [(a, Rational)]<br>
                <br>
                <br>
                --Main> multAllExt (l1,1 % 4)<br>
                --[('a',1 % 6),('b',1 % 12)]</div>
              <div class="gmail_default" style="font-size:large"><br>
              </div>
              <div class="gmail_default" style="font-size:large"><br>
              </div>
              <div class="gmail_default" style="font-size:large">i get
                this error:</div>
              <div class="gmail_default" style="font-size:large"><br>
              </div>
              <div class="gmail_default" style="font-size:large">GHCi,
                version 8.4.3: <a href="http://www.haskell.org/ghc/"
                  moz-do-not-send="true">http://www.haskell.org/ghc/</a> 
                :? for help<br>
                Prelude> :load monade.hs<br>
                [1 of 1] Compiling Main             ( monade.hs,
                interpreted )<br>
                <br>
                monade.hs:21:10: error:<br>
                    • No instance for (Applicative Prob)<br>
                        arising from the superclasses of an instance
                declaration<br>
                    • In the instance declaration for ‘Monad Prob’<br>
                   |<br>
                21 | instance Monad Prob where<br>
                   |          ^^^^^^^^^^<br>
                Failed, no modules loaded.<br>
              </div>
              <div class="gmail_default" style="font-size:large"><br>
              </div>
              <div class="gmail_default" style="font-size:large">it
                fails when i add the last part of the example:</div>
              <div class="gmail_default" style="font-size:large"><br>
              </div>
              <div class="gmail_default" style="font-size:large">instance
                Monad Prob where<br>
                  return x = Prob [(x,1%1)]<br>
                  m >>= f = flatten (fmap f m)<br>
                  fail _ = Prob []</div>
              <div class="gmail_default" style="font-size:large"><br>
              </div>
              <div class="gmail_default" style="font-size:large"><br>
              </div>
              <div class="gmail_default" style="font-size:large">seems
                the Monad needs an instance of the Applicative to be
                instanciated...</div>
              <div class="gmail_default" style="font-size:large"><br>
              </div>
              <div class="gmail_default" style="font-size:large">what is
                wrong? <br>
              </div>
              <div class="gmail_default" style="font-size:large"><br>
              </div>
              <div class="gmail_default" style="font-size:large">regards,</div>
              <div class="gmail_default" style="font-size:large">Damien<br>
              </div>
            </div>
          </div>
        </div>
      </div>
      <br>
      <fieldset class="mimeAttachmentHeader"></fieldset>
      <pre class="moz-quote-pre" wrap="">_______________________________________________
Haskell-Cafe mailing list
To (un)subscribe, modify options or view archives go to:
<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>
Only members subscribed via the mailman list are allowed to post.</pre>
    </blockquote>
  </body>
</html>