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. Re:  testing IO code (Maurizio Vitale)
   2.  There has been discussion on matrix operations and cache
      thrashing; does management think using Haskell would lead to cash
      thrashing? (KC)
   3. Re:  Saving intermediate calculations (Henk-Jan van Tuyl)
   4. Re:  Equivalent of IO Monad in other functional   languages?
      (Heinrich Apfelmus)
   5. Re:  There has been discussion on matrix operations and cache
      thrashing; does management think using Haskell would lead to cash
      thrashing? (emacstheviking)


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

Message: 1
Date: Mon, 16 Mar 2015 09:06:01 -0700
From: Maurizio Vitale <[email protected]>
To: [email protected],  The Haskell-Beginners Mailing
        List - Discussion of primarily beginner-level topics related to
        Haskell <[email protected]>
Cc: Haskell-cafe Cafe <[email protected]>
Subject: Re: [Haskell-beginners] testing IO code
Message-ID:
        <caaelbql5v5b5ke+uztptguw+bm35ecd4fpnrdnno6kkjhwa...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

Thanks!
This is what I had in mind, except that I'm new too Haskell so I tried
English instead of code for expressing it :-)
I'll also check the IOSpec package Paul suggested,

On Mon, Mar 16, 2015 at 7:40 AM, Sumit Sahrawat, Maths & Computing, IIT
(BHU) <[email protected]> wrote:

> On 16 March 2015 at 19:51, Maurizio Vitale <[email protected]> wrote:
>
>> suppose I have a restricted IO monad, RIO that only exposes readFile.
>> and then I have a monad SIO that will eventually provide a virtual file
>> system from a map path->content, also with a readFile function returning
>> SIO(String).
>>
>> What is the way to write a function parseFile that can operate in both
>> monads so that I can use SIO for testing? should I define a third monad
>> CompileMonad that has instances for both RIO and SIO and then having
>> parseFile :: CompileMonad ast?
>>
>
> You might be able to do something like,
>
>     class MonadIO m => ProvidesReadFile m where
>         readFile :: FilePath -> m String
>
>     instance ProvidesReadFile RIO where
>         readFile = readFileRIO    -- the RIO specific readFile
>
>     instance ProvidesReadFile SIO where
>         readFile = readFileSIO    -- the SIO specific readFile
>
>     parseFile :: ProvidesReadFile m => FilePath -> m ast
>     parseFile = do
>         f <- readFile
>         let ast = parse f    -- the pure parser
>         return ast           -- works for both monads
>
>
>> Thanks,
>>
>>   Maurizio
>>
>> _______________________________________________
>> Beginners mailing list
>> [email protected]
>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>>
>>
> This is more suitable for the haskell-cafe. I am posting it there so that
> more people might comment on it.
> HTH.
>
> --
> Regards
>
> Sumit Sahrawat
>
> _______________________________________________
> 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/20150316/4f16f2ef/attachment-0001.html>

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

Message: 2
Date: Mon, 16 Mar 2015 13:53:13 -0700
From: KC <[email protected]>
To: Haskell Beginners <[email protected]>, [email protected]
Subject: [Haskell-beginners] There has been discussion on matrix
        operations and cache thrashing; does management think using Haskell
        would lead to cash thrashing?
Message-ID:
        <camlkxykmywx24mx6-bwkss04pioylkidobkdkgmvualafg+...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

There has been discussion on matrix operations and cache thrashing; does
management think using Haskell would lead to cash thrashing?

What could change management's mind?

--
--

Sent from an expensive device which will be obsolete in a few months! :D

Casey
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://mail.haskell.org/pipermail/beginners/attachments/20150316/a9b7c89c/attachment-0001.html>

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

Message: 3
Date: Mon, 16 Mar 2015 23:55:56 +0100
From: "Henk-Jan van Tuyl" <[email protected]>
To: "Abhinav Kalawatia" <[email protected]>,
        "[email protected]" <[email protected]>
Subject: Re: [Haskell-beginners] Saving intermediate calculations
Message-ID: <op.xvl4nmo3pz0j5l@alquantor>
Content-Type: text/plain; charset=iso-8859-15; format=flowed;
        delsp=yes

On Thu, 12 Mar 2015 16:34:19 +0100, Abhinav Kalawatia
<[email protected]> wrote:

> Hi Henk,
> I hope you are well :)
> Thanks for your help with the solution for saving the intermediate  
> calculations. Henk, could you please help me understand the following  
> code snippet?
> ewma1 a (x:xs) = reverse $ foldl' f [x] xs
>     where f m@(x':xs') n = ((a * n) + ((1 - a) * x')):m

You can do mathematical substitution:

ewma1 a (x:xs) = reverse $ foldl' f [x] xs
         where f m@(x':xs') n = ((a * n) + ((1 - a) * x')):m

+ (definition of foldl, which performs the same calculation as foldl',  
though not strict)

foldl f z []     =  z
foldl f z (x:xs) =  foldl f (f z x) xs

=> (substitute definition of foldl in ewma1)

ewma1 a (x1:x2:xs) = reverse $ foldl' f (f [x1] x2) xs
         where f m@(x':xs') n = ((a * n) + ((1 - a) * x')):m

=> (substitute f)

ewma1 a (x1:x2:xs) = reverse $ foldl' f (((a * x2) + ((1 - a) * x1)):[x1])  
xs
         where f m@(x':xs') n = ((a * n) + ((1 - a) * x')):m

Repeat the last two steps until the list is processed.

There is a tool to display this automatically: Hat, but I could not get it  
to run properly on my Windows PC.
The homepage is at:
   http://projects.haskell.org/hat/

Regards,
Henk-Jan

-- 
Folding@home
What if you could share your unused computer power to help find a cure? In
just 5 minutes you can join the world's biggest networked computer and get
us closer sooner. Watch the video.
http://folding.stanford.edu/


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

Message: 4
Date: Tue, 17 Mar 2015 10:29:53 +0100
From: Heinrich Apfelmus <[email protected]>
To: [email protected]
Subject: Re: [Haskell-beginners] Equivalent of IO Monad in other
        functional      languages?
Message-ID: <[email protected]>
Content-Type: text/plain; charset=UTF-8; format=flowed

Frerich Raabe wrote:
> 
> I also used to share this "Every function in Haskell is pure, as long as 
> it does not use any of the unsafe* functions" view but by now I'm 
> wondering whether that's really a useful definition. It may be true that
> 
>   putStrLn :: String -> IO ()
> 
> is pure in the sense that it only yields a 'recipe' for printing the 
> given string instead of actually printing it. However, I think it's 
> important to realize that putStrLn *could* actually yield a poisoned 
> recipe, something which not *only* prints a string but which also plays 
> a sound at 4AM. And the types won't let you know whether this is the case.
> 
> Hence, even though putStrLn may be pure in the classical 'same input 
> yields same output' sense, I wondr whether it's more useful to consider 
> putStrLn to be impure on the grounds that a value of type 'IO a' means 
> "anything can happen, and whatever happens doesn't necessarily only 
> depend on the arguments".

Well, purity of functions is still a useful concept, because it provides 
a useful invariant in the types. For instance, the well-known function

     map :: (a -> b) -> [a] -> [b]

may assume that the first argument always returns equal results given 
equal arguments and hence can be applied in any order and as often as 
desired. On the other hand,

     mapM :: (a -> IO b) -> [a] -> IO [b]

may not assume that and must be careful about the sequence of operations.


Of course, an action  IO a  means that "anything can happen", but I 
don't think it's useful to call that "impure". It's a good thing that 
the nastiness of the `IO` type constructor is separated cleanly from the 
properties of the function arrow `->`.

That leaves the question of how to reason about `IO` programs. This is 
explored in detail in Simon Peyton-Jones' tutorial

"Tackling the awkward squad: monadic input/output, concurrency, 
exceptions, and foreign-language calls in Haskell"

http://research.microsoft.com/en-us/um/people/simonpj/papers/marktoberdorf/


You may also like "The Operational Monad Tutorial", which doesn't cover 
IO, but tries to explain how other monads can be understood and 
implemented in terms of operational semantics:

   http://apfelmus.nfshost.com/articles/operational-monad.html


Best regards,
Heinrich Apfelmus

--
http://apfelmus.nfshost.com



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

Message: 5
Date: Tue, 17 Mar 2015 11:52:46 +0000
From: emacstheviking <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] There has been discussion on matrix
        operations and cache thrashing; does management think using Haskell
        would lead to cash thrashing?
Message-ID:
        <CAEiEuULt7AgXbn52SwyLEHvvOE6wZjn7uryNNrzprYR2=4v...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

If "consultancy" was involved then cash thrashing is always an issue ;)


On 16 March 2015 at 20:53, KC <[email protected]> wrote:

> There has been discussion on matrix operations and cache thrashing; does
> management think using Haskell would lead to cash thrashing?
>
> What could change management's mind?
>
> --
> --
>
> Sent from an expensive device which will be obsolete in a few months! :D
>
> Casey
>
>
> _______________________________________________
> 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/20150317/d0b3c32a/attachment-0001.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 47
*****************************************

Reply via email to