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. Saving intermediate calculations (Abhinav Kalawatia)
2. GHC not buying what I am offering this afternoon (Geoffrey Bays)
3. Re: GHC not buying what I am offering this afternoon
(Joel Williamson)
4. Re: GHC not buying what I am offering this afternoon
(Geoffrey Bays)
----------------------------------------------------------------------
Message: 1
Date: Mon, 9 Mar 2015 15:47:06 +0000 (UTC)
From: Abhinav Kalawatia <[email protected]>
To: "[email protected]" <[email protected]>
Subject: [Haskell-beginners] Saving intermediate calculations
Message-ID:
<[email protected]>
Content-Type: text/plain; charset="utf-8"
? Hello,
I?am facing a slight difficulty trying to?do something while saving
intermediate calculations
week ?? actual_?sales(a) ??? forecast(f) ?????????????? ??????? forecast(f)
???????????????????????????? forecast(f)
?1 ?????????? 20 ??????????????????????? ?f1 = a1 ????????????????????????????
f1 = 20 ?????????????????????????????????? f1 = 20
?2 ?????????? 27 ??????????????????????? ?f2 = f1 + 0.5*(a1 - f1)??????? f2 =
20 +0.5(20-20) ????????????? ?f2 = 20
?3 ?????????? 25 ??????????????????????? ?f3 = f2 +? 0.5*(a2-f2)?????????f3 =
20+0.5*(27-20)???????????? ? f3=23.5
?4 ?????????? 22
When I execute?a function to achieve this?in Haskell, I get the forecast for
the fourth period. Can I save the values for intermediate period(1..3) also?
Please find my Haskell code below:
a = 0.5
ipt = [20,27,25,22]
avg :: [Double] -> Double
avg (x:xs) = (a*x) + (1-a)*(avg xs)
avg [] = 0
Could you please help me with this, thanking you in anticipation
Regards,Abhinav
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://mail.haskell.org/pipermail/beginners/attachments/20150309/1524dd95/attachment-0001.html>
------------------------------
Message: 2
Date: Mon, 9 Mar 2015 16:07:23 -0400
From: Geoffrey Bays <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: [Haskell-beginners] GHC not buying what I am offering this
afternoon
Message-ID:
<cad8ukx4otih6nlgmveuxpjt64-kvzifue7to6mvqf+cm8gq...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
My main function looks like this:
main :: [IO()]
main = do
let stud1 = Student {name = "Geoff", average = -99.0, grades =
[66,77,88]}
let stud2 = Student {name = "Doug", average = -99.0, grades =
[77,88,99]}
let stud3 = Student {name = "Ron", average = -99.0, grades = [55,66,77]}
let studList = [stud1,stud2]
let newList = calcAvg studList
[putStrLn $ show s | s <- newList]
--putStrLn $ show (newList !! 0)
--putStrLn $ show (newList !! 1)
With this final line, putStrLn $ show (newList !! 0), the type IO () in the
function declaration compiles fine.
But with [putStrLn $ show s | s <- newList] as the final line, [IO ()] in
the function declaration will not compile, I get this error:
Couldn't match expected type `IO t0' with actual type `[IO ()]'
What does the declared type need to be for a final line of:
[putStrLn $ show s | s <- newList] ???
Thanks,
Geoffrey
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://mail.haskell.org/pipermail/beginners/attachments/20150309/c2bab9f6/attachment-0001.html>
------------------------------
Message: 3
Date: Mon, 09 Mar 2015 20:15:59 +0000
From: Joel Williamson <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] GHC not buying what I am offering
this afternoon
Message-ID:
<CAJGxSeoXeSqcbkW4cuPkMj5r8wDxSMyKmYK_P+qaX0=mcnh...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
main must have type IO a. Hoogle tells me that to convert [IO a] -> IO [a],
you should use the function sequence. Try applying that to your final line.
On Mon, 9 Mar 2015 16:07 Geoffrey Bays <[email protected]> wrote:
> My main function looks like this:
>
> main :: [IO()]
> main = do
> let stud1 = Student {name = "Geoff", average = -99.0, grades =
> [66,77,88]}
> let stud2 = Student {name = "Doug", average = -99.0, grades =
> [77,88,99]}
> let stud3 = Student {name = "Ron", average = -99.0, grades =
> [55,66,77]}
> let studList = [stud1,stud2]
> let newList = calcAvg studList
> [putStrLn $ show s | s <- newList]
> --putStrLn $ show (newList !! 0)
> --putStrLn $ show (newList !! 1)
>
> With this final line, putStrLn $ show (newList !! 0), the type IO () in
> the function declaration compiles fine.
> But with [putStrLn $ show s | s <- newList] as the final line, [IO ()] in
> the function declaration will not compile, I get this error:
>
> Couldn't match expected type `IO t0' with actual type `[IO ()]'
>
> What does the declared type need to be for a final line of:
> [putStrLn $ show s | s <- newList] ???
>
> Thanks,
>
> Geoffrey
>
> _______________________________________________
> 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/20150309/3b21d9c1/attachment-0001.html>
------------------------------
Message: 4
Date: Mon, 9 Mar 2015 16:25:02 -0400
From: Geoffrey Bays <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] GHC not buying what I am offering
this afternoon
Message-ID:
<cad8ukx6t01b+zb0rgsvvywyvk03jn8n9z-cogxynchpxggi...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
Thanks, Joel.
Putting the type IO [()] in the main declaration and this as the final line
of the main function does do the trick:
sequence [putStrLn $ show s | s <- newList]
But this is the kind of thing that makes Haskell types difficult for
beginners to work with...
Geoffrey
On Mon, Mar 9, 2015 at 4:15 PM, Joel Williamson <[email protected]
> wrote:
> main must have type IO a. Hoogle tells me that to convert [IO a] -> IO
> [a], you should use the function sequence. Try applying that to your final
> line.
>
> On Mon, 9 Mar 2015 16:07 Geoffrey Bays <[email protected]> wrote:
>
>> My main function looks like this:
>>
>> main :: [IO()]
>> main = do
>> let stud1 = Student {name = "Geoff", average = -99.0, grades =
>> [66,77,88]}
>> let stud2 = Student {name = "Doug", average = -99.0, grades =
>> [77,88,99]}
>> let stud3 = Student {name = "Ron", average = -99.0, grades =
>> [55,66,77]}
>> let studList = [stud1,stud2]
>> let newList = calcAvg studList
>> [putStrLn $ show s | s <- newList]
>> --putStrLn $ show (newList !! 0)
>> --putStrLn $ show (newList !! 1)
>>
>> With this final line, putStrLn $ show (newList !! 0), the type IO () in
>> the function declaration compiles fine.
>> But with [putStrLn $ show s | s <- newList] as the final line, [IO ()] in
>> the function declaration will not compile, I get this error:
>>
>> Couldn't match expected type `IO t0' with actual type `[IO ()]'
>>
>> What does the declared type need to be for a final line of:
>> [putStrLn $ show s | s <- newList] ???
>>
>> Thanks,
>>
>> Geoffrey
>>
>> _______________________________________________
>> 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
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://mail.haskell.org/pipermail/beginners/attachments/20150309/58165721/attachment.html>
------------------------------
Subject: Digest Footer
_______________________________________________
Beginners mailing list
[email protected]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
------------------------------
End of Beginners Digest, Vol 81, Issue 33
*****************************************