Send Beginners mailing list submissions to
        [email protected]

To subscribe or unsubscribe via the World Wide Web, visit
        http://mail.haskell.org/cgi-bin/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.  Using IO values for computations (Dananji Liyanage)
   2. Re:  Using IO values for computations (Magnus Therning)
   3. Re:  Couldn't match expected type `(a0 -> [a0]) -> [a0]',
      with actual type `[a0]' (Grzegorz Milka)
   4. Re:  Using IO values for computations (Kostiantyn Rybnikov)
   5. Re:  Using IO values for computations (Dananji Liyanage)


----------------------------------------------------------------------

Message: 1
Date: Mon, 25 May 2015 12:14:32 +0530
From: Dananji Liyanage <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Subject: [Haskell-beginners] Using IO values for computations
Message-ID:
        <CAAPsY8zM3Kjboj6NdmPmVcHCq63jXmupV+JQGgFkjJp=3zo...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

Hi All,

I'm writing a code, where the input is read from a text file using:
readValues = readFile "Input.txt"

Since the type of this is 'IO String', I can't use this in the consequent
functions.

For an example: I want to split this as follows within another function

extractInput url method template
  | isURI url == True = getList values components
  | otherwise = []
  where components = splitTemplate readValues
        values = getURL (splitURL url) method

This gives the following error:

 Couldn't match type ?IO String? with ?[Char]?
    Expected type: String
      Actual type: IO String

How can I solve this?

Thanks in advance!

-- 
Regards,
Dananji Liyanage
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://mail.haskell.org/pipermail/beginners/attachments/20150525/057ca6cd/attachment-0001.html>

------------------------------

Message: 2
Date: Mon, 25 May 2015 14:29:12 +0200
From: Magnus Therning <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Using IO values for computations
Message-ID:
        <caaexw5tlntdv6yxwxc5tv0tjimhucamsg1gqjyusn9ksshg...@mail.gmail.com>
Content-Type: text/plain; charset=UTF-8

On 25 May 2015 at 08:44, Dananji Liyanage <[email protected]> wrote:
> Hi All,
>
> I'm writing a code, where the input is read from a text file using:
> readValues = readFile "Input.txt"
>
> Since the type of this is 'IO String', I can't use this in the consequent
> functions.
>
> For an example: I want to split this as follows within another function
>
> extractInput url method template
>   | isURI url == True = getList values components
>   | otherwise = []
>   where components = splitTemplate readValues
>         values = getURL (splitURL url) method
>
> This gives the following error:
>
>  Couldn't match type ?IO String? with ?[Char]?
>     Expected type: String
>       Actual type: IO String
>
> How can I solve this?

Start with reading some basic Haskell book/tutorial.  That should tell
you how to e.g. use 'do' notation, or `liftM`, to achieve what you
want.

/M

-- 
Magnus Therning                      OpenPGP: 0xAB4DFBA4
email: [email protected]   jabber: [email protected]
twitter: magthe               http://therning.org/magnus


------------------------------

Message: 3
Date: Sat, 23 May 2015 10:29:30 +0200
From: Grzegorz Milka <[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 `(a0 ->
        [a0]) -> [a0]', with actual type `[a0]'
Message-ID: <[email protected]>
Content-Type: text/plain; charset="windows-1252"

Hi,

The faulty expression is this one:

   ((number `mod` 10 ): acc) (toDigits' (number `mod` 10))

The first expression: ((number `mod` 10 ): acc) is a list. You
concatenate a number to acc.

Therefore what you are doing is calling a list with an argument:
(toDigits' (number `mod` 10)).

That's what the error says. The first expression is called with one
argument, but its is a list ([a0]), which is not a function, therefore
can not be called. I think you meant something like:

    toDigits' acc number   = toDigits'  ((number `mod` 10 ): acc)
(number `div` 10)

Best,
Greg

On 23.05.2015 08:58, Roelof Wobben wrote:
> Hello,
>
> For some reasons my file's are corrupted.
> I had repair them with success except this one.
>
> Here is the code :
>
> toDigits  number
>   | number <= 0   = []
>   | otherwise     = toDigits' [] number
>   where
>     toDigits' acc 0  = acc
>     toDigits' acc number   = ((number `mod` 10 ): acc) (toDigits'
> (number `mod` 10))
>
> main = print $ toDigits 123
>
>
> and here is the error:
>
> Couldn't match expected type `(a0 -> [a0]) -> [a0]'
>                 with actual type `[a0]'
>     The function `(number `mod` 10) : acc' is applied to one argument,
>     but its type `[a0]' has none
>     In the expression:
>       ((number `mod` 10) : acc) (toDigits' (number `mod` 10))
>     In an equation for toDigits':
>         toDigits' acc number
>           = ((number `mod` 10) : acc) (toDigits' (number `mod` 10))
>
>
> Roelof
>
>
> ---
> Dit e-mailbericht is gecontroleerd op virussen met Avast
> antivirussoftware.
> http://www.avast.com
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners


-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: OpenPGP digital signature
URL: 
<http://mail.haskell.org/pipermail/beginners/attachments/20150523/cfe657e4/attachment-0001.sig>

------------------------------

Message: 4
Date: Mon, 25 May 2015 19:23:04 +0300
From: Kostiantyn Rybnikov <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Using IO values for computations
Message-ID:
        <CAAbahfS=5vokqxh_mzm9efd3txuxuzdh3qdg7o0s36vjndw...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

Dananji,

Haskell explicitly separates "pure" from "impure", so "readFile <file>"
returns not a string, but rather an action, which tells haskell to read a
string. In order to "use" a result of some IO action as a pure value, you
have several ways, most popula of which is a do-notation.

main :: IO ()
main = do
    s <- readFile "somefile.txt"
    putStrLn (show (doSplit s))

In the code above, variable "s" is "pure", it has type String and you can
use it as you want. Do-notation is essentially a sugar to callback
mechanism, where in order to use a value of some IO-computation you write a
function-callback that will be called with a pure value of computation
result. This code is the same as previous one, but without do-notation:

main :: IO ()
main =
    readFile "somefile.txt" >>= (\s ->
    putStrLn (show (doSplit s)))

I highly recommend reading "Learn You A Haskell" book
http://learnyouahaskell.com/ , which explained these concepts really well
to me.

On Mon, May 25, 2015 at 9:44 AM, Dananji Liyanage <[email protected]> wrote:

> Hi All,
>
> I'm writing a code, where the input is read from a text file using:
> readValues = readFile "Input.txt"
>
> Since the type of this is 'IO String', I can't use this in the consequent
> functions.
>
> For an example: I want to split this as follows within another function
>
> extractInput url method template
>   | isURI url == True = getList values components
>   | otherwise = []
>   where components = splitTemplate readValues
>         values = getURL (splitURL url) method
>
> This gives the following error:
>
>  Couldn't match type ?IO String? with ?[Char]?
>     Expected type: String
>       Actual type: IO String
>
> How can I solve this?
>
> Thanks in advance!
>
> --
> Regards,
> Dananji Liyanage
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://mail.haskell.org/pipermail/beginners/attachments/20150525/8873b94b/attachment-0001.html>

------------------------------

Message: 5
Date: Tue, 26 May 2015 08:59:01 +0530
From: Dananji Liyanage <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Using IO values for computations
Message-ID:
        <caapsy8zbvan9alo5dfb0xehrd1uj4zbc1mezh04bnowwnmh...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

Thank you for the nice explanation!

I understood it for some extent, and will read further on I/O.

On Mon, May 25, 2015 at 9:53 PM, Kostiantyn Rybnikov <[email protected]> wrote:

> Dananji,
>
> Haskell explicitly separates "pure" from "impure", so "readFile <file>"
> returns not a string, but rather an action, which tells haskell to read a
> string. In order to "use" a result of some IO action as a pure value, you
> have several ways, most popula of which is a do-notation.
>
> main :: IO ()
> main = do
>     s <- readFile "somefile.txt"
>     putStrLn (show (doSplit s))
>
> In the code above, variable "s" is "pure", it has type String and you can
> use it as you want. Do-notation is essentially a sugar to callback
> mechanism, where in order to use a value of some IO-computation you write a
> function-callback that will be called with a pure value of computation
> result. This code is the same as previous one, but without do-notation:
>
> main :: IO ()
> main =
>     readFile "somefile.txt" >>= (\s ->
>     putStrLn (show (doSplit s)))
>
> I highly recommend reading "Learn You A Haskell" book
> http://learnyouahaskell.com/ , which explained these concepts really well
> to me.
>
> On Mon, May 25, 2015 at 9:44 AM, Dananji Liyanage <[email protected]>
> wrote:
>
>> Hi All,
>>
>> I'm writing a code, where the input is read from a text file using:
>> readValues = readFile "Input.txt"
>>
>> Since the type of this is 'IO String', I can't use this in the
>> consequent functions.
>>
>> For an example: I want to split this as follows within another function
>>
>> extractInput url method template
>>   | isURI url == True = getList values components
>>   | otherwise = []
>>   where components = splitTemplate readValues
>>         values = getURL (splitURL url) method
>>
>> This gives the following error:
>>
>>  Couldn't match type ?IO String? with ?[Char]?
>>     Expected type: String
>>       Actual type: IO String
>>
>> How can I solve this?
>>
>> Thanks in advance!
>>
>> --
>> Regards,
>> Dananji Liyanage
>>
>> _______________________________________________
>> Beginners mailing list
>> [email protected]
>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>>
>>
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
>


-- 
Regards,
Dananji Liyanage
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://mail.haskell.org/pipermail/beginners/attachments/20150526/b53426a1/attachment.html>

------------------------------

Subject: Digest Footer

_______________________________________________
Beginners mailing list
[email protected]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners


------------------------------

End of Beginners Digest, Vol 83, Issue 55
*****************************************

Reply via email to