[Haskell-cafe] strange error message

Semen Trygubenko / Семен Тригубенко semen at trygub.com
Thu Mar 27 14:50:07 UTC 2014


On Thu, Mar 27, 2014 at 03:23:35PM +0300, Yuras Shumovich wrote:
> It seems to be already fixed:
> https://ghc.haskell.org/trac/ghc/changeset/b988dc39a06278acc2373ba9a40ee08da0127411/ghc

Ah! Great — in ghc 7.8.

Until then let's ignore the middle statement (indeed I thought it might be a bug) — I've
replaced it with "<snip> below:


test.hs:10:15:
    Couldn't match type `[[a2]]' with `Int'
    Expected type: Int -> Int
      Actual type: [[a2]] -> Int

    <snip>

    In the first argument of `(==)', namely `(length . head) r'
    In the expression: (length . head) r == 0


(1) Why are we biasing the programmer to expect
one thing (the function is wrong) and not the other (r is wrong)?
I.e., would the programmer benefit from inclusion of the "alternative view" as well?

(2) Is it worth stating the context next to the "expected type" message,
so that it is clearer what "[[a2]] -> Int" and "expected type" refer to?

E.g.,


test.hs:10:15:
    Couldn't match type `[[a2]]' with `Int'

      Actual type (length . head) :: [[a2]] -> Int
    Expected type                 :: Int -> Int

    OR

      Actual type r :: Int
    Expected type   :: [[a2]]

    <snip>

    In the first argument of `(==)', namely `(length . head) r'
    In the expression: (length . head) r == 0



Many thanks for your kind hel4p,
S.





> 
> 
> Thanks,
> Yuras
> 
> On Thu, 2014-03-27 at 13:16 +0100, Erik Hesselink wrote:
> > Could you create a code snippet that reproduces the error?
> > 
> > Erik
> > 
> > On Thu, Mar 27, 2014 at 1:09 PM, Semen Trygubenko / Семен Тригубенко
> > <semen at trygub.com> wrote:
> > > Hi Ivan,
> > >
> > > On Thu, Mar 27, 2014 at 11:28:33AM +0000, Ivan Perez wrote:
> > >> What is the type of head?
> > >> What is the type of length?
> > >> What is the type of length.head?
> > >> What is the type of r?
> > >
> > > Prelude> :t head
> > > head :: [a] -> a
> > > Prelude> :t length
> > > length :: [a] -> Int
> > > Prelude> :t (length . head)
> > > (length . head) :: [[a]] -> Int
> > > Prelude>
> > >
> > > r is of type Int.
> > >
> > > [Apologies — I thought the above is deducible from the error message I've included (below).]
> > >
> > > Clearly, this is a type error as Int is passed in where [[a]] is expected.
> > > However, my question is relating to the middle bit of the error message,
> > > namely:
> > >
> > >     (The function `length . head' is applied to one argument,
> > >     but its type `[[a2]] -> Int' has only one)
> > >
> > > Many thanks,
> > > S.
> > >
> > >
> > >
> > >
> > >> On 27 March 2014 02:36, Semen Trygubenko / Семен Тригубенко <
> > >> semen at trygub.com> wrote:
> > >>
> > >> > Dear Haskell-Cafe,
> > >> >
> > >> > Every now and then I get error messages when compiling Haskell code :).
> > >> > Sometimes of the sort:
> > >> >
> > >> > test.hs:10:15:
> > >> >     Couldn't match type `[[a2]]' with `Int'
> > >> >     Expected type: Int -> Int
> > >> >       Actual type: [[a2]] -> Int
> > >> >     The function `length . head' is applied to one argument,
> > >> >     but its type `[[a2]] -> Int' has only one
> > >> >     In the first argument of `(==)', namely `(length . head) r'
> > >> >     In the expression: (length . head) r == 0
> > >> >
> > >> > Is the middle part of the error message
> > >> >
> > >> > (The function `length . head' is applied to one argument,
> > >> > but its type `[[a2]] -> Int' has only one)
> > >> >
> > >> > expected to be confusing like that sometimes?
> > >> >
> > >> > The line in question, FWIW, is
> > >> >
> > >> > Right r -> if (length . head) r == 0
> > >> >
> > >> > It appears as one of the two entries in a case statement, pattern matching
> > >> > on Right constructor.
> > >> >
> > >> > Many thanks,
> > >> > S.
> > >> >
> > >> >
> > >> >
> > >> > --
> > >> > Семен Тригубенко http://trygub.com
> > >> >
> > >> > _______________________________________________
> > >> > Haskell-Cafe mailing list
> > >> > Haskell-Cafe at haskell.org
> > >> > http://www.haskell.org/mailman/listinfo/haskell-cafe
> > >> >
> > >> >
> > >
> > > --
> > > Семен Тригубенко http://trygub.com
> > >
> > > _______________________________________________
> > > Haskell-Cafe mailing list
> > > Haskell-Cafe at haskell.org
> > > http://www.haskell.org/mailman/listinfo/haskell-cafe
> > >
> > _______________________________________________
> > Haskell-Cafe mailing list
> > Haskell-Cafe at haskell.org
> > http://www.haskell.org/mailman/listinfo/haskell-cafe
> 
> 

-- 
Семен Тригубенко http://trygub.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 196 bytes
Desc: not available
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20140327/6e7d4807/attachment.sig>


More information about the Haskell-Cafe mailing list