Send Beginners mailing list submissions to
[email protected]
To subscribe or unsubscribe via the World Wide Web, visit
http://www.haskell.org/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
[email protected]
You can reach the person managing the list at
[email protected]
When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."
Today's Topics:
1. Type error in function binding (bahad?r altan)
2. Re: Type error in function binding (Mats Rauhala)
3. Re: Type error in function binding (Markus L?ll)
4. Re: Type error in function binding (Nathan H?sken)
5. a problem with happy ABCParser example (kak dod)
6. Syntax error in input (bahad?r altan)
7. Re: Syntax error in input (bahad?r altan)
----------------------------------------------------------------------
Message: 1
Date: Mon, 2 Apr 2012 15:50:41 +0100 (BST)
From: bahad?r altan <[email protected]>
Subject: [Haskell-beginners] Type error in function binding
To: "[email protected]" <[email protected]>
Message-ID:
<[email protected]>
Content-Type: text/plain; charset="iso-8859-1"
Hi.
I'm trying to write a code which counts the number of ?'a's ?in a string.
it looks like this :
mycounter st =
if st == [] then 0
else if head st == 'a' then 1 + mycounter tail st else mycounter tail st
but it gives this error :?
ERROR "deneme.hs":19 - Type error in function binding
*** Term ? ? ? ? ? :mycounter
*** Type ? ? ? ? ? : [Char] -> b
*** Does not match : ([a] -> [a]) -> [Char] -> b
*** Because ? ? ? ?: unification would give infinite type
I have no idea about what I'm doing wrong. Can you help me with this please?
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20120402/dfb3fd9e/attachment-0001.htm>
------------------------------
Message: 2
Date: Mon, 2 Apr 2012 17:59:42 +0300
From: Mats Rauhala <[email protected]>
Subject: Re: [Haskell-beginners] Type error in function binding
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset="iso-8859-1"
On 15:50 Mon 02 Apr , bahad?r altan wrote:
> Hi.
> I'm trying to write a code which counts the number of ?'a's ?in a string.
> it looks like this :
>
> mycounter st =
> if st == [] then 0
> else if head st == 'a' then 1 + mycounter tail st else mycounter tail st
>
> but it gives this error :?
> ERROR "deneme.hs":19 - Type error in function binding
> *** Term ? ? ? ? ? :mycounter
> *** Type ? ? ? ? ? : [Char] -> b
> *** Does not match : ([a] -> [a]) -> [Char] -> b
> *** Because ? ? ? ?: unification would give infinite type
>
> I have no idea about what I'm doing wrong. Can you help me with this please?
I didn't verify, but it could be that you need parenthesize the `counter tail
st`
part.
A different kind of solution could be:
counter [] = 0
counter ('a':xs) = 1 + counter xs
counter (_:xs) = counter xs
Or maybe even: `length $ filter (== 'a') xs`
--
Mats Rauhala
MasseR
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: not available
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20120402/71ffd3b2/attachment-0001.pgp>
------------------------------
Message: 3
Date: Mon, 2 Apr 2012 18:00:39 +0300
From: Markus L?ll <[email protected]>
Subject: Re: [Haskell-beginners] Type error in function binding
To: bahad?r altan <[email protected]>, [email protected]
Message-ID:
<CALdaiuCZ5GM1doOfV4vo7R00reYfTAxU9o=h4A8iR3S_6=p...@mail.gmail.com>
Content-Type: text/plain; charset=ISO-8859-1
You're missing some parenthesis. Instead of "mycounter tail st" write
"mycounter (tail st)".
On Mon, Apr 2, 2012 at 5:50 PM, bahad?r altan <[email protected]> wrote:
> Hi.
> I'm trying to write a code which counts the number of ?'a's ?in a string.
> it looks like this :
>
> mycounter st =
> if st == [] then 0
> else if head st == 'a' then 1 + mycounter tail st else mycounter tail st
>
> but it gives this error :
> ERROR "deneme.hs":19 - Type error in function binding
> *** Term ? ? ? ? ? :mycounter
> *** Type ? ? ? ? ? : [Char] -> b
> *** Does not match : ([a] -> [a]) -> [Char] -> b
> *** Because ? ? ? ?: unification would give infinite type
>
> I have no idea about what I'm doing wrong. Can you help me with this please?
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>
--
Markus L?ll
------------------------------
Message: 4
Date: Mon, 02 Apr 2012 17:04:48 +0200
From: Nathan H?sken <[email protected]>
Subject: Re: [Haskell-beginners] Type error in function binding
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1
I think you are just missing parentheses:
mycounter st =
if st == [] then 0
else if head st == 'a' then 1 + mycounter (tail st) else mycounter (tail st)
On 04/02/2012 04:50 PM, bahad?r altan wrote:
> Hi.
> I'm trying to write a code which counts the number of 'a's in a string.
> it looks like this :
>
> mycounter st =
> if st == [] then 0
> else if head st == 'a' then 1 + mycounter tail st else mycounter tail st
>
> but it gives this error :
> ERROR "deneme.hs":19 - Type error in function binding
> *** Term :mycounter
> *** Type : [Char] -> b
> *** Does not match : ([a] -> [a]) -> [Char] -> b
> *** Because : unification would give infinite type
>
> I have no idea about what I'm doing wrong. Can you help me with this please?
>
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
------------------------------
Message: 5
Date: Mon, 2 Apr 2012 21:56:04 +0530
From: kak dod <[email protected]>
Subject: [Haskell-beginners] a problem with happy ABCParser example
To: [email protected]
Message-ID:
<CAJ4=wnelywrpmd_pwu3_yehg95gqxzgod1p7uewnfi0203o...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"
Hello,
Greeting everybody.
I am a beginner of Haskell. I am trying out the happy.
When I compiled the happy grammar file for the ABCParser given at
http://www.haskell.org/happy/doc/html/sec-AttributeGrammarExample.html
I did get a Haskell source file.
Then I loaded this file, named "abc.hs" into ghci.
There is a function called "parse" available to us.
GHCi shows its type to be
parse :: [Char] -> [Char]
But no matter whatever input I give to the parse function, it always gives
the following error:
"*** Exception: parse error
Here are some sample inputs on the GHCi shell:
*ABCParser> parse "abc"
"*** Exception: parse error
*ABCParser> parse "a"
"*** Exception: parse error
*ABCParser> parse ""
"*** Exception: parse error
*ABCParser> parse "aabbcc"
"*** Exception: parse error
What is the problem?
The happy grammar is here:
{
module ABCParser (parse) where
}
%tokentype { Char }
%token a { 'a' }
%token b { 'b' }
%token c { 'c' }
%token newline { '\n' }
%attributetype { Attrs a }
%attribute value { a }
%attribute len { Int }
%name parse abcstring
%%
abcstring
: alist blist clist newline
{ $$ = $1 ++ $2 ++ $3
; $2.len = $1.len
; $3.len = $1.len
}
alist
: a alist
{ $$ = $1 : $2
; $$.len = $2.len + 1
}
| { $$ = []; $$.len = 0 }
blist
: b blist
{ $$ = $1 : $2
; $2.len = $$.len - 1
}
| { $$ = []
; where failUnless ($$.len == 0) "blist wrong length"
}
clist
: c clist
{ $$ = $1 : $2
; $2.len = $$.len - 1
}
| { $$ = []
; where failUnless ($$.len == 0) "clist wrong length"
}
{
happyError = error "parse error"
failUnless b msg = if b then () else error msg
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20120402/1edb7dd4/attachment-0001.htm>
------------------------------
Message: 6
Date: Mon, 2 Apr 2012 17:44:16 +0100 (BST)
From: bahad?r altan <[email protected]>
Subject: [Haskell-beginners] Syntax error in input
To: "[email protected]" <[email protected]>
Message-ID:
<[email protected]>
Content-Type: text/plain; charset="iso-8859-1"
Hi,?
I wrote that function:
?wordCount x = length(words x)
but I get this :
ERROR "a.hs":73 - Syntax error in input (unexpected symbol "wordCount")
Can you tell me how can I get rid of this error please? Thanks..
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20120402/2f861e7f/attachment-0001.htm>
------------------------------
Message: 7
Date: Mon, 2 Apr 2012 17:47:03 +0100 (BST)
From: bahad?r altan <[email protected]>
Subject: Re: [Haskell-beginners] Syntax error in input
To: "[email protected]" <[email protected]>
Message-ID:
<[email protected]>
Content-Type: text/plain; charset="iso-8859-1"
I found the error, silly mistake, sorry :-)
________________________________
From: bahad?r altan <[email protected]>
To: "[email protected]" <[email protected]>
Sent: Monday, 2 April 2012, 19:44
Subject: Syntax error in input
Hi,?
I wrote that function:
?wordCount x = length(words x)
but I get this :
ERROR "a.hs":73 - Syntax error in input (unexpected symbol "wordCount")
Can you tell me how can I get rid of this error please? Thanks..
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20120402/ca716c1a/attachment.htm>
------------------------------
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
End of Beginners Digest, Vol 46, Issue 1
****************************************