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.  eve / did = 0.talktalktalk... (Alexander.Vladislav.Popov )
   2.  Trying to compile my first program that imports  another
      program (Mitchell Kaplan)
   3. Re:  Trying to compile my first program that      imports another
      program (MAN)
   4. Re:  Trying to compile my first program that      imports another
      program (Dean Herington)


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

Message: 1
Date: Thu, 22 Apr 2010 16:12:24 +0600
From: "Alexander.Vladislav.Popov "
        <[email protected]>
Subject: [Haskell-beginners] eve / did = 0.talktalktalk...
To: [email protected]
Message-ID:
        <[email protected]>
Content-Type: text/plain; charset="iso-8859-1"

Dear Everebody.

Hepl me please to parallelize (parallel computing of evedidtalk
function) the rebus:

-- | eve / did = 0.talktalktalk...

ten :: Integral a => [a]
ten = [0..9]

infixr 7 /:

(/:) :: (Integral a) => [a] -> [a] -> [a]
(/:) [] _ = [0]
(/:) _ [] = []
(/:) x y = coldiv (getInteger x) (getInteger y)

getInteger :: (Num a) => [a] -> a
getInteger = foldl ((+) . (*10)) 0

coldiv :: (Integral a) => a -> a -> [a]
coldiv a b = q : if r == 0
                 then []
                 else coldiv (r * 10) b
             where
               (q, r) = a `quotRem` b

evedidtalk = [ ([e, v, e], [d, i, d], [t, a, l, k]) |
            e <- ten,
            v <- ten, v /= e,
            d <- ten, d /= e, d /= v,
            i <- ten, i /= e, i /= v, i /= d,
            t <- ten, t /= e, t /= v, t /= d, t /= i,
            a <- ten, a /= e, a /= v, a /= d, a /= i, a /= t,
            l <- ten, l /= e, l /= v, l /= d, l /= i, l /= t, l /= a,
            k <- ten, k /= e, k /= v, k /= d, k /= i, k /= t, k /= a, k /=
l,
            take 9 ([e, v, e] /: [d, i, d]) == [0, t, a, l, k, t, a, l, k]
          ]

Sincerely, Alexander
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
http://www.haskell.org/pipermail/beginners/attachments/20100422/26bf2160/attachment-0001.html

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

Message: 2
Date: Sun, 25 Apr 2010 21:07:36 -0400
From: "Mitchell Kaplan" <[email protected]>
Subject: [Haskell-beginners] Trying to compile my first program that
        imports another program
To: <[email protected]>
Message-ID: <84f7441dd51d4ca6bd9d2dc380a88...@home93f2a7f3c6>
Content-Type: text/plain; charset="us-ascii"

Hi,

 

I created (with help) a function to test for prime numbers.  It worked well
enough for now in ghci.

 

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

    f x n y

      | n>y = True

      | rem x n == 0 = False 

      | otherwise = f x (n+1) y

 

    primeQ x = f x 2 y

      where 

      y = floor(sqrt(fromIntegral x))

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

 

I then wanted to create object code so that I could import it.  It seemed
that I had to precede the above with the 2 lines:

    

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

    module Prime

    where

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

 

I ran:

   ghc -c prime.hs, and created prime.o and prime.hi.

 

 

Next, I wanted to write a program to import and use this function.

 

I wrote:

 

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

    module Main () where

    import Prime

    main = primeQ 123

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

 

I tried to compile this with:

    ghc -o test Main.hs prime.o

 

I got the following error:

    Main.hs:5:0:

        Couldn't match expected type 'IO t' against inferred type 'Bool'

        In the expression: main

        When checking the type of the function 'main'

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

 

First I'd like a hint as to what I need to do to make this work.

 

It's pretty obvious that I don't know what I'm doing with regard to types.
Also, I have no idea if I have to name this module Main, but when I didn't
the compiler complained about that.

 

In the function that I think I had to re-write to make object code, I wound
up with 2 where statements, which worries me.

 

I'd really appreciate any help in getting me unraveled.

 

        Mitchell

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
http://www.haskell.org/pipermail/beginners/attachments/20100425/7e83cc44/attachment-0001.html

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

Message: 3
Date: Sun, 25 Apr 2010 22:25:32 -0300
From: MAN <[email protected]>
Subject: Re: [Haskell-beginners] Trying to compile my first program
        that    imports another program
To: Mitchell Kaplan <[email protected]>
Cc: [email protected]
Message-ID: <1272245132.4137.9.ca...@dy-book>
Content-Type: text/plain; charset="UTF-8"

Hi, Mitchell

First of all, you don't really need to compile your module Prime to be
able to import it. Supposing you just want to, though:

Your funcion primeO is 'pure', it work on numbers only, and will return
the same results for the same arguments every time, without "launching
missiles" or side-effects of any kind.

The main function (in the Main module), which is the 'main entry
point' (like in C), is of type 'IO ()' ... this means a lot, and you
should really look into types for Haskell; but in a nutshell, it means
the function 'main' may have side-effects (like printing to stdout, or
opening a socket, deleting a file, etc) which cannot be predicted.

Haskell is very careful as to keep pure code pure, and non-pure code,
well, non-pure... [check out 'monads']. The 'main' function is of type
'IO ()', so all functions called by it must have type 'IO something'.
[IO is a monad]. Your function prime0 is of type 'Bool', so you need to
inject it into the 'IO' [get it into the monad]. This is done with the
function 'return' (which is quite different to that of C):

module Main where
import Prime
main = return (primeQ 123)

BTW, your Haskell program must have a Main module. You will write your
modules with "module SomeThing where", and name that file SomeThing.hs;
the Main module can have any filename you want, though.


El dom, 25-04-2010 a las 21:07 -0400, Mitchell Kaplan escribió:
> Hi,
> 
>  
> 
> I created (with help) a function to test for prime numbers.  It worked
> well enough for now in ghci.
> 
>  
> 
> ----------------
> 
>     f x n y
> 
>       | n>y = True
> 
>       | rem x n == 0 = False 
> 
>       | otherwise = f x (n+1) y
> 
>  
> 
>     primeQ x = f x 2 y
> 
>       where 
> 
>       y = floor(sqrt(fromIntegral x))
> 
> ---------------
> 
>  
> 
> I then wanted to create object code so that I could import it.  It
> seemed that I had to precede the above with the 2 lines:
> 
>     
> 
> ----------------
> 
>     module Prime
> 
>     where
> 
> ----------------
> 
>  
> 
> I ran:
> 
>    ghc –c prime.hs, and created prime.o and prime.hi.
> 
>  
> 
>  
> 
> Next, I wanted to write a program to import and use this function.
> 
>  
> 
> I wrote:
> 
>  
> 
> ------------
> 
>     module Main () where
> 
>     import Prime
> 
>     main = primeQ 123
> 
> ------------
> 
>  
> 
> I tried to compile this with:
> 
>     ghc –o test Main.hs prime.o
> 
>  
> 
> I got the following error:
> 
>     Main.hs:5:0:
> 
>         Couldn’t match expected type ‘IO t’ against inferred type
> ‘Bool’
> 
>         In the expression: main
> 
>         When checking the type of the function ‘main’
> 
> ----------------
> 
>  
> 
> First I’d like a hint as to what I need to do to make this work.
> 
>  
> 
> It’s pretty obvious that I don’t know what I’m doing with regard to
> types.  Also, I have no idea if I have to name this module Main, but
> when I didn’t the compiler complained about that.
> 
>  
> 
> In the function that I think I had to re-write to make object code, I
> wound up with 2 where statements, which worries me.
> 
>  
> 
> I’d really appreciate any help in getting me unraveled.
> 
>  
> 
>         Mitchell
> 
>  
> 
> 
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners




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

Message: 4
Date: Mon, 26 Apr 2010 01:06:09 -0400
From: Dean Herington <[email protected]>
Subject: Re: [Haskell-beginners] Trying to compile my first program
        that    imports another program
To: MAN <[email protected]>,     Mitchell Kaplan
        <[email protected]>
Cc: [email protected]
Message-ID: <a06240800c7facea12...@[192.168.1.100]>
Content-Type: text/plain; charset="iso-8859-1" ; format="flowed"

MAN's nutshell explanation is good, and his 
rewrite of the Main module is type-correct.  But 
note that the result of the `main` action (of 
type IO t for some type t) is deliberately 
discarded, so you probably want something more 
useful, such as:

module Main where
import Prime
main = print (primeQ 123)

Dean

At 10:25 PM -0300 4/25/10, MAN wrote:
>Hi, Mitchell
>
>First of all, you don't really need to compile your module Prime to be
>able to import it. Supposing you just want to, though:
>
>Your funcion primeO is 'pure', it work on numbers only, and will return
>the same results for the same arguments every time, without "launching
>missiles" or side-effects of any kind.
>
>The main function (in the Main module), which is the 'main entry
>point' (like in C), is of type 'IO ()' ... this means a lot, and you
>should really look into types for Haskell; but in a nutshell, it means
>the function 'main' may have side-effects (like printing to stdout, or
>opening a socket, deleting a file, etc) which cannot be predicted.
>
>Haskell is very careful as to keep pure code pure, and non-pure code,
>well, non-pure... [check out 'monads']. The 'main' function is of type
>'IO ()', so all functions called by it must have type 'IO something'.
>[IO is a monad]. Your function prime0 is of type 'Bool', so you need to
>inject it into the 'IO' [get it into the monad]. This is done with the
>function 'return' (which is quite different to that of C):
>
>module Main where
>import Prime
>main = return (primeQ 123)
>
>BTW, your Haskell program must have a Main module. You will write your
>modules with "module SomeThing where", and name that file SomeThing.hs;
>the Main module can have any filename you want, though.
>
>
>El dom, 25-04-2010 a las 21:07 -0400, Mitchell Kaplan escribió:
>>  Hi,
>>
>> 
>>
>>  I created (with help) a function to test for prime numbers.  It worked
>>  well enough for now in ghci.
>>
>> 
>>
>>  ----------------
>>
>>      f x n y
>>
>>        | n>y = True
>>
>>        | rem x n == 0 = False
>>
>>        | otherwise = f x (n+1) y
>>
>> 
>>
>>      primeQ x = f x 2 y
>>
>>        where
>>
>>        y = floor(sqrt(fromIntegral x))
>>
>>  ---------------
>>
>> 
>>
>>  I then wanted to create object code so that I could import it.  It
>>  seemed that I had to precede the above with the 2 lines:
>>
>>    
>>
>>  ----------------
>>
>>      module Prime
>>
>>      where
>>
>>  ----------------
>>
>> 
>>
>>  I ran:
>>
>>     ghc -c prime.hs, and created prime.o and prime.hi.
>>
>> 
>>
>> 
>>
>>  Next, I wanted to write a program to import and use this function.
>>
>> 
>>
>>  I wrote:
>>
>> 
>>
>>  ------------
>>
>>      module Main () where
>>
>>      import Prime
>>
>>      main = primeQ 123
>>
>>  ------------
>>
>> 
>>
>>  I tried to compile this with:
>>
>>      ghc -o test Main.hs prime.o
>>
>> 
>>
>>  I got the following error:
>>
>>      Main.hs:5:0:
>>
>>          Couldn't match expected type 'IO t' against inferred type
>>  'Bool'
>>
>>          In the expression: main
>>
>>          When checking the type of the function 'main'
>>
>>  ----------------
>>
>> 
>>
>>  First I'd like a hint as to what I need to do to make this work.
>>
>> 
>>
>>  It's pretty obvious that I don't know what I'm doing with regard to
>>  types.  Also, I have no idea if I have to name this module Main, but
>>  when I didn't the compiler complained about that.
>>
>> 
>>
>>  In the function that I think I had to re-write to make object code, I
>>  wound up with 2 where statements, which worries me.
>>
>> 
>>
>>  I'd really appreciate any help in getting me unraveled.
>>
>> 
>>
>  >         Mitchell


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

_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners


End of Beginners Digest, Vol 22, Issue 39
*****************************************

Reply via email to