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. Re: Couldn't match expected type ?IO ()? with actual type
[Integer] (Roelof Wobben)
2. Re: Couldn't match expected type ?IO ()? with actual type
[Integer] (Nadir Sampaoli)
3. Re: Couldn't match expected type ?IO ()? with actual type
[Integer] (Max Voit)
4. Re: Couldn't match expected type ?IO ()? with actual type
[Integer] (Roelof Wobben)
5. Re: Couldn't match expected type ?IO ()? with actual type
[Integer] (Marcin Mrotek)
6. Re: Couldn't match expected type ?IO ()? with actual type
[Integer] (Norbert Melzer)
7. Re: Couldn't match expected type ?IO ()? with actual type
[Integer] (Roelof Wobben)
----------------------------------------------------------------------
Message: 1
Date: Thu, 05 Feb 2015 13:25:16 +0100
From: Roelof Wobben <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Couldn't match expected type ?IO ()?
with actual type [Integer]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=utf-8; format=flowed
Max Voit schreef op 5-2-2015 om 13:01:
> Hi Roelof,
>
> On Thu, 05 Feb 2015 12:37:12 +0100
> Roelof Wobben <[email protected]> wrote:
>
>> main :: IO ()
>> main = do
>> toDigits 123
>> src/Main.hs@14:5-14:17
>> Couldn't match expected type ?IO ()? with actual type
>> [Integer]
>> ? In a stmt of a 'do' block: toDigits 123 In the expression: do
>> { toDigits 123 }
> since your do block consists only of one expression,
> actually your main looks like:
>
> main :: IO ()
> main = toDigits 123
>
> Perhaps this explains where the problem lies.
>
> Considering, however, do-notation: The last statement of a do-block
> needs to be an expression of the type of the do-block. Translating
> do-notation to bind operator sequences[1] may be helpful in
> understanding this.
>
> best,
> Max
>
> [1] http://en.wikibooks.org/wiki/Haskell/do_notation
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
Thanks,
Another question : how can I display the array ?
putStrln works only for strings,
Roelof
------------------------------
Message: 2
Date: Thu, 5 Feb 2015 13:26:54 +0100
From: Nadir Sampaoli <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Couldn't match expected type ?IO ()?
with actual type [Integer]
Message-ID:
<CAFYwTdQcxNuqNm6nbfmbRXupd=cziedqwkznhtnch3ctzuy...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
"Roelof Wobben":
>
> I have this :
>
> -- | Main entry point to the application.
> module Main where
>
>
> -- | convert a number to a array in pieces where a negative number will
be a empty array.
> toDigits :: Integer -> [Integer]
> toDigits n
> | n < 0 = []
> | otherwise = n/10 : []
>
> -- | The main entry point.
> main :: IO ()
> main = do
> toDigits 123
First of all, what do you expect from your program?
The problem with your code is that `main` declares type `IO ()` in its
signatures but its body has another type, [Integer].
What do you think is wrong with the compiler's output?
--
Nadir
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20150205/d59faff0/attachment-0001.html>
------------------------------
Message: 3
Date: Thu, 5 Feb 2015 13:35:11 +0100
From: Max Voit <[email protected]>
To: [email protected]
Subject: Re: [Haskell-beginners] Couldn't match expected type ?IO ()?
with actual type [Integer]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=US-ASCII
On Thu, 05 Feb 2015 13:25:16 +0100
Roelof Wobben <[email protected]> wrote:
> Another question : how can I display the array ?
>
> putStrln works only for strings,
Yep, so you need to convert it to a string and putStrLn that. Kindly
enough typing ":i []" into ghci tells you, that lists have an instance
for "show".
Anonther option would be to convert every single list element to a
string and putStrLn that. "map" comes in handy here (or mapM_ if you
directly want to use print instead of putStrLn . show).
best,
Max
------------------------------
Message: 4
Date: Thu, 05 Feb 2015 14:07:02 +0100
From: Roelof Wobben <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Couldn't match expected type ?IO ()?
with actual type [Integer]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=windows-1252; format=flowed
Max Voit schreef op 5-2-2015 om 13:35:
> On Thu, 05 Feb 2015 13:25:16 +0100
> Roelof Wobben <[email protected]> wrote:
>
>> Another question : how can I display the array ?
>>
>> putStrln works only for strings,
> Yep, so you need to convert it to a string and putStrLn that. Kindly
> enough typing ":i []" into ghci tells you, that lists have an instance
> for "show".
>
> Anonther option would be to convert every single list element to a
> string and putStrLn that. "map" comes in handy here (or mapM_ if you
> directly want to use print instead of putStrLn . show).
>
> best,
> Max
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>
Thanks that part worked fine.
One part I cannot figure out is how to make this :
-- | Main entry point to the application.
module Main where
-- | convert a number to a array in pieces where a negative number will
be a empty array.
toDigits :: Integer -> [Integer]
toDigits n
| n < 0 = []
| otherwise = n `mod` 10 : []
-- | The main entry point.
main :: IO ()
main = do
print $ toDigits 123
Now it showing only [1] or [23]
I have to find out how I can do something like this toDigits 23 [1]
But I cannot do this that way because it has to be Integer -> [Integer]
Who has a tip for me ?
Roelof
------------------------------
Message: 5
Date: Thu, 5 Feb 2015 17:29:08 +0100
From: Marcin Mrotek <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Couldn't match expected type ?IO ()?
with actual type [Integer]
Message-ID:
<CAJcfPz=GTqOH21xLMYsQj=zshkqm-k+fedwx7ftjpzev6yu...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
Well, toDigits is always finishing its work after dividing the input number
once, and always returns lists of at most one element. You need it to call
itself recursively until it's done, and append the calculated digit to the
result:
toDigits :: Integer -> [Integer]
toDigits n
| n <= 0 = []
| otherwise = n `mod` 10 : toDigits (n `div` 10)
The <= is necessary, otherwise the function would loop infinitely on 0.
This version will print the digits in reverse, so you might move the code
to a local function in toDigits, and make toDigit call it and then reverse
the result.
I'd strongly recommend reading a Haskell tutorial (for example
http://learnyouahaskell.com ) to learn the basics.
Kind regards,
Marcin Mrotek
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20150205/86184ea4/attachment-0001.html>
------------------------------
Message: 6
Date: Thu, 5 Feb 2015 18:16:37 +0100
From: Norbert Melzer <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Couldn't match expected type ?IO ()?
with actual type [Integer]
Message-ID:
<ca+bcvstyaeozj_ldcrzepgob22wuovd7g1topg9xe0da8cy...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
Am 05.02.2015 17:29 schrieb "Marcin Mrotek" <[email protected]>:
>
> Well, toDigits is always finishing its work after dividing the input
number once, and always returns lists of at most one element. You need it
to call itself recursively until it's done, and append the calculated digit
to the result:
>
> toDigits :: Integer -> [Integer]
> toDigits n
> | n <= 0 = []
> | otherwise = n `mod` 10 : toDigits (n `div` 10)
This doesn't feel right:
toDigits 10 = 0 : toDigits 1 = 0 : 1 : toDigits 0 = 0 : 1 : [] = [0,1]
I'd expect the result to be [1,0]...
>
> The <= is necessary, otherwise the function would loop infinitely on 0.
This version will print the digits in reverse, so you might move the code
to a local function in toDigits, and make toDigit call it and then reverse
the result.
>
> I'd strongly recommend reading a Haskell tutorial (for example
http://learnyouahaskell.com ) to learn the basics.
>
> Kind regards,
> Marcin Mrotek
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20150205/3032db7c/attachment-0001.html>
------------------------------
Message: 7
Date: Thu, 05 Feb 2015 20:03:31 +0100
From: Roelof Wobben <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Couldn't match expected type ?IO ()?
with actual type [Integer]
Message-ID: <[email protected]>
Content-Type: text/plain; charset="us-ascii"
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20150205/6afbb815/attachment.html>
------------------------------
Subject: Digest Footer
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
------------------------------
End of Beginners Digest, Vol 80, Issue 5
****************************************