Maybe what you are missing is an argument to the app_len function?<br><br>Am Freitag, 30. Oktober 2015 schrieb David Banas :<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi all,<br>
<br>
I thought I had a simple way to determine the “length" (i.e. - number of elements in) of a Foldable Applicative container:<br>
<br>
    import Prelude hiding (sum)<br>
    import Data.Foldable (Foldable(..), sum)<br>
    import Control.Applicative<br>
<br>
    -- Calculate the "length" (i.e. - number of elements in) an Applicative container.<br>
    app_len :: (Applicative f, Foldable f) => f a -> Int<br>
    app_len = sum $ pure 1<br>
<br>
but I didn’t:<br>
<br>
app_len_test.hs:9:11:<br>
    Could not deduce (Foldable t0) arising from a use of ‘sum’<br>
    from the context (Applicative f, Foldable f)<br>
      bound by the type signature for<br>
                 app_len :: (Applicative f, Foldable f) => f a -> Int<br>
      at app_len_test.hs:8:12-52<br>
    The type variable ‘t0’ is ambiguous<br>
    Note: there are several potential instances:<br>
      instance Foldable ((,) a) -- Defined in ‘Data.Foldable’<br>
      instance GHC.Arr.Ix i => Foldable (GHC.Arr.Array i)<br>
        -- Defined in ‘Data.Foldable’<br>
      instance Foldable (Const m) -- Defined in ‘Data.Foldable’<br>
      ...plus four others<br>
    In the expression: sum<br>
    In the expression: sum $ pure 1<br>
    In an equation for ‘app_len’: app_len = sum $ pure 1<br>
<br>
app_len_test.hs:9:17:<br>
    Could not deduce (Applicative t0) arising from a use of ‘pure’<br>
    from the context (Applicative f, Foldable f)<br>
      bound by the type signature for<br>
                 app_len :: (Applicative f, Foldable f) => f a -> Int<br>
      at app_len_test.hs:8:12-52<br>
    The type variable ‘t0’ is ambiguous<br>
    Note: there are several potential instances:<br>
      instance Data.Monoid.Monoid a => Applicative ((,) a)<br>
        -- Defined in ‘Control.Applicative’<br>
      instance Applicative ((->) a) -- Defined in ‘Control.Applicative’<br>
      instance Control.Arrow.Arrow a =><br>
               Applicative (Control.Arrow.ArrowMonad a)<br>
        -- Defined in ‘Control.Applicative’<br>
      ...plus 14 others<br>
    In the second argument of ‘($)’, namely ‘pure 1’<br>
    In the expression: sum $ pure 1<br>
    In an equation for ‘app_len’: app_len = sum $ pure 1<br>
<br>
Can anyone help me understand what I’m missing?<br>
<br>
Thanks, and have a great weekend,<br>
-db<br>
<br>
_______________________________________________<br>
Haskell-Cafe mailing list<br>
<a href="javascript:;" onclick="_e(event, 'cvml', 'Haskell-Cafe@haskell.org')">Haskell-Cafe@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe</a><br>
</blockquote>