Send Beginners mailing list submissions to
        beginners@haskell.org

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
        beginners-requ...@haskell.org

You can reach the person managing the list at
        beginners-ow...@haskell.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1.  Type inference in ST monad? (Aurimas)
   2. Re:  Type inference in ST monad? (David McBride)
   3. Re:  Type inference in ST monad? (Aurimas)
   4. Re:  How Haskell Fits Into an Operating System / API
      Environment (Magnus Therning)
   5. Re:  How Haskell Fits Into an Operating System / API
      Environment (Henk-Jan van Tuyl)


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

Message: 1
Date: Mon, 19 Aug 2013 04:18:28 +0300
From: Aurimas <aurimas.anskai...@vgtu.lt>
To: beginners@haskell.org
Subject: [Haskell-beginners] Type inference in ST monad?
Message-ID: <52117264.4010...@vgtu.lt>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed

I have the following code which does not compile due to explicit type 
annotation
(ST s Double). Error message says usual thing about "s" type variables.

----------------------------------------------------------------------------------------------------------
import Control.Monad.ST
import System.Random.MWC (initialize, uniformR, Gen)
import Control.Monad.Loops (whileM)
import Data.Vector (singleton)
import Data.Word(Word32)

main :: IO ()
main = do
   print $ runSimulation 1

runSimulation :: Word32 -> [Int]
runSimulation seed = runST $ do
   gen <- initialize (singleton seed)
   whileM  (do r1 <- uniformR (-1.0, 1.0) gen :: ST s Double -- does not 
compile due to this
               if r1 > 0.0 then return True else return False)
           (do r2 <- uniformR (0, 10) gen
               if r2 > 5 then return r2 else return 0)
---------------------------------------------------------------------------------------------------------

if I rewrite runSimulation like this (below), everything is OK.

---------------------------------------------------------------------------------------------------------
runSimulation :: Word32 -> [Int]
runSimulation seed = runST $ do
   gen <- initialize (singleton seed)
   whileM  (do r1 <- tempFun gen
               if r1 > 0.0 then return True else return False)
           (do r2 <- uniformR (0, 10) gen
               if r2 > 5 then return r2 else return 0)
     where tempFun :: Gen s -> ST s Double    -- this line automatically 
provides required type annotation
           tempFun g = uniformR (-1.0, 1.0) g
---------------------------------------------------------------------------------------------------------

Ca somebody explain what's wrong with the first version?

Best Regards,
Aurimas




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

Message: 2
Date: Sun, 18 Aug 2013 22:04:26 -0400
From: David McBride <toa...@gmail.com>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <beginners@haskell.org>
Subject: Re: [Haskell-beginners] Type inference in ST monad?
Message-ID:
        <CAN+Tr43yuhheV9qtDo1=uyrayhcmjy-znynr-yvcdnlpsto...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"

I'm not exactly sure why you get the error, but the easiest way to fix it
is just to type it this way:

runSimulation :: Word32 -> [Int]
runSimulation seed = runST $ do
  gen <- initialize (singleton seed)
  whileM  (do r1 <- uniformR (-1.0, 1.0 :: Double) gen
              if r1 > 0.0 then return True else return False)
          (do r2 <- uniformR (0, 10 :: Int) gen
              if r2 > 5 then return r2 else return 0)

It has something to do with the forall s in runST, although I'm not
completely sure what.



On Sun, Aug 18, 2013 at 9:18 PM, Aurimas <aurimas.anskai...@vgtu.lt> wrote:

> I have the following code which does not compile due to explicit type
> annotation
> (ST s Double). Error message says usual thing about "s" type variables.
>
> ------------------------------**------------------------------**
> ------------------------------**----------------
> import Control.Monad.ST
> import System.Random.MWC (initialize, uniformR, Gen)
> import Control.Monad.Loops (whileM)
> import Data.Vector (singleton)
> import Data.Word(Word32)
>
> main :: IO ()
> main = do
>   print $ runSimulation 1
>
> runSimulation :: Word32 -> [Int]
> runSimulation seed = runST $ do
>   gen <- initialize (singleton seed)
>   whileM  (do r1 <- uniformR (-1.0, 1.0) gen :: ST s Double -- does not
> compile due to this
>               if r1 > 0.0 then return True else return False)
>           (do r2 <- uniformR (0, 10) gen
>               if r2 > 5 then return r2 else return 0)
> ------------------------------**------------------------------**
> ------------------------------**---------------
>
> if I rewrite runSimulation like this (below), everything is OK.
>
> ------------------------------**------------------------------**
> ------------------------------**---------------
> runSimulation :: Word32 -> [Int]
> runSimulation seed = runST $ do
>   gen <- initialize (singleton seed)
>   whileM  (do r1 <- tempFun gen
>               if r1 > 0.0 then return True else return False)
>           (do r2 <- uniformR (0, 10) gen
>               if r2 > 5 then return r2 else return 0)
>     where tempFun :: Gen s -> ST s Double    -- this line automatically
> provides required type annotation
>           tempFun g = uniformR (-1.0, 1.0) g
> ------------------------------**------------------------------**
> ------------------------------**---------------
>
> Ca somebody explain what's wrong with the first version?
>
> Best Regards,
> Aurimas
>
>
> ______________________________**_________________
> Beginners mailing list
> Beginners@haskell.org
> http://www.haskell.org/**mailman/listinfo/beginners<http://www.haskell.org/mailman/listinfo/beginners>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20130818/be2f64e1/attachment-0001.html>

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

Message: 3
Date: Mon, 19 Aug 2013 08:36:10 +0300
From: Aurimas <aurimas.anskai...@vgtu.lt>
To: beginners@haskell.org
Subject: Re: [Haskell-beginners] Type inference in ST monad?
Message-ID: <5211aeca.6050...@vgtu.lt>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed

On 08/19/2013 05:04 AM, David McBride wrote:
> I'm not exactly sure why you get the error, but the easiest way to fix 
> it is just to type it this way:
>
> runSimulation :: Word32 -> [Int]
> runSimulation seed = runST $ do
>   gen <- initialize (singleton seed)
>   whileM  (do r1 <- uniformR (-1.0, 1.0 :: Double) gen
>               if r1 > 0.0 then return True else return False)
>           (do r2 <- uniformR (0, 10 :: Int) gen
>               if r2 > 5 then return r2 else return 0)
>
> It has something to do with the forall s in runST, although I'm not 
> completely sure what.
>
Thanks, this is clearly the most easy way to fix the problem. But the 
question remains - why the line
"do r1 <- uniformR (-1.0, 1.0 :: Double) gen"    cannot be annotated 
with ST s Double?



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

Message: 4
Date: Mon, 19 Aug 2013 10:18:11 +0200
From: Magnus Therning <mag...@therning.org>
To: beginners@haskell.org
Subject: Re: [Haskell-beginners] How Haskell Fits Into an Operating
        System / API Environment
Message-ID: <20130819081811.gb1...@mteis.semcon.se>
Content-Type: text/plain; charset="us-ascii"

On Sun, Aug 18, 2013 at 10:55:00AM +0200, Heinrich Apfelmus wrote:
> Philippe Sismondi wrote:
> >I am the original poster on this. [..]
[...]
> >At the risk of pouring fuel on the fire, I would ask: Can anyone
> >point me to scientific studies quantifying the benefits of pure
> >functional languages? I expect they exist, but I am interested not
> >just in lack of errors, but in overall productivity. (It's easy to
> >avoid program bugs: just write programs that don't do anything, or
> >don't write any software at all.)
> 
> You know well that (1) such studies are hard to design for any
> language and (2) nobody asks for studies that quantify the benefits
> of imperative languages, simply because they happen to be the status
> quo.
> 
> Still, there are some interesting case studies, for instance
> 
>   P Hudak and M P Jones
>   "Haskell vs. Ada vs. C++ vs. Awk vs. ...
>    An Experiment in Software Prototyping Productivity"
>   http://haskell.cs.yale.edu/?post_type=publication&p=366

There are also a few articles on Erlang, and I believe there's good
reason to believe the results with that language can be transferred to
other "languages without assignment".

- Productivity gains with Erlarng
  http://dl.acm.org/citation.cfm?id=1362710
  slides: http://is.gd/BgGZyh
  (behind a paywall, I haven't found a freely available copy)

- Breakthrough in software design productivity through the use of
  declarative programming
  http://www.sciencedirect.com/science/article/pii/S0925527397807669
  (behind a paywall, I haven't found a freely available copy)

/M

-- 
Magnus Therning                      OpenPGP: 0xAB4DFBA4 
email: mag...@therning.org   jabber: mag...@therning.org
twitter: magthe               http://therning.org/magnus


Perl is another example of filling a tiny, short-term need, and then
being a real problem in the longer term.
     -- Alan Kay
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 230 bytes
Desc: not available
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20130819/6eed9bf1/attachment-0001.sig>

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

Message: 5
Date: Mon, 19 Aug 2013 12:52:20 +0200
From: "Henk-Jan van Tuyl" <hjgt...@chello.nl>
To: beginners@haskell.org, "Magnus Therning" <mag...@therning.org>
Subject: Re: [Haskell-beginners] How Haskell Fits Into an Operating
        System / API Environment
Message-ID: <op.w118hjt4pz0...@zen5.arnhem.chello.nl>
Content-Type: text/plain; charset=iso-8859-15; format=flowed;
        delsp=yes

On Mon, 19 Aug 2013 10:18:11 +0200, Magnus Therning <mag...@therning.org>  
wrote:

> There are also a few articles on Erlang, and I believe there's good
> reason to believe the results with that language can be transferred to
> other "languages without assignment".
>
> - Productivity gains with Erlarng
>   http://dl.acm.org/citation.cfm?id=1362710
>   slides: http://is.gd/BgGZyh
>   (behind a paywall, I haven't found a freely available copy)
>

For free:
   "Four-fold Increase in Productivity and Quality"
   Ulf Wiger, FemSYS 2001, Munich
   http://www.erlang.se/publications/Ulf_Wiger.pdf

Regards,
Henk-Jan van Tuyl


-- 
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/


http://Van.Tuyl.eu/
http://members.chello.nl/hjgtuyl/tourdemonad.html
Haskell programming
--



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

Subject: Digest Footer

_______________________________________________
Beginners mailing list
Beginners@haskell.org
http://www.haskell.org/mailman/listinfo/beginners


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

End of Beginners Digest, Vol 62, Issue 19
*****************************************

Reply via email to