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. Re:  Problems with one of my first examples (Tillmann Rendel)
   2.  unix-2.3.1.0 failed during the building phase (Renick Bell)
   3.  MVar and Par .. (Mozhgan)
   4.  Re: A type level programming question (Apfelmus, Heinrich)
   5. Re:  Re: A type level programming question (Levi Stephen)
   6.  Defining a containing function on polymorphic    list (Raeck Zhao)
   7.  Re: [Haskell-cafe] Defining a containing function on
      polymorphic list (Andrew Wagner)


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

Message: 1
Date: Mon, 15 Dec 2008 23:45:08 +0100
From: Tillmann Rendel <ren...@daimi.au.dk>
Subject: Re: [Haskell-beginners] Problems with one of my first
        examples
Cc: beginners@haskell.org
Message-ID: <4946ddf4.2060...@daimi.au.dk>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed

Jeff C. Britton wrote:
> do nums <- askForNumbers; map sqrt nums
> 
> ERROR - Type error in final generator
> *** Term           : map sqrt nums
> *** Type           : [Integer]
> *** Does not match : IO a

Here (map sqrt nums) has type [Integer], so you cannot use it in a do 
expression for IO. Instead, you have to write something which produces 
an IO action.

> do nums <- askForNumbers; printList nums  -- works fine

Here, (printList nums) has type IO (), so it fits into the do expression 
and everything is fine.

If you want to print the list of square roots, you have to say so:

   do nums <- askForNumbers; printList (map sqrt nums)

Tillmann


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

Message: 2
Date: Tue, 16 Dec 2008 15:33:18 +0900
From: "Renick Bell" <ren...@gmail.com>
Subject: [Haskell-beginners] unix-2.3.1.0 failed during the building
        phase
To: beginners@haskell.org
Message-ID:
        <b6105e870812152233y6fe8f4dek1f14051af6c83...@mail.gmail.com>
Content-Type: text/plain; charset=ISO-8859-1

I was trying to install this package and received this error:

[a lot of stuff]
Preprocessing library unix-2.3.1.0...
Building unix-2.3.1.0...
[ 1 of 21] Compiling System.Posix.Signals ( System/Posix/Signals.hs,
dist/build/System/Posix/Signals.o )
[ 2 of 21] Compiling System.Posix.Signals.Exts (
dist/build/System/Posix/Signals/Exts.hs,
dist/build/System/Posix/Signals/Exts.o )
[ 3 of 21] Compiling System.Posix.User (
dist/build/System/Posix/User.hs, dist/build/System/Posix/User.o )
[ 4 of 21] Compiling System.Posix.Unistd (
dist/build/System/Posix/Unistd.hs, dist/build/System/Posix/Unistd.o )
[ 5 of 21] Compiling System.Posix.Time (
dist/build/System/Posix/Time.hs, dist/build/System/Posix/Time.o )
[ 6 of 21] Compiling System.Posix.Resource (
dist/build/System/Posix/Resource.hs,
dist/build/System/Posix/Resource.o )
[ 7 of 21] Compiling System.Posix.Process.Internals (
System/Posix/Process/Internals.hs,
dist/build/System/Posix/Process/Internals.o )
[ 8 of 21] Compiling System.Posix.Error ( System/Posix/Error.hs,
dist/build/System/Posix/Error.o )
[ 9 of 21] Compiling System.Posix.Files (
dist/build/System/Posix/Files.hs, dist/build/System/Posix/Files.o )

System/Posix/Files.hsc:504:42:
    Ambiguous occurrence `c_rename'
    It could refer to either `System.Posix.Files.c_rename', defined at
System/Posix/Files.hsc:507:3
                          or `System.Posix.Internals.c_rename',
imported from System.Posix.Internals at System/Posix/Files.hsc:93:0-28
cabal: Error: some packages failed to install:
unix-2.3.1.0 failed during the building phase. The exception was:
exit: ExitFailure 1

Being a beginner, I'm not sure what to do here...

-- 
Renick Bell
http://the3rd2nd.com


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

Message: 3
Date: Tue, 16 Dec 2008 02:45:23 -0800 (PST)
From: Mozhgan <mozhgan_...@yahoo.com>
Subject: [Haskell-beginners] MVar and Par ..
To: beginners@haskell.org
Message-ID: <48504.12378...@web90406.mail.mud.yahoo.com>
Content-Type: text/plain; charset="us-ascii"

Hi .. Hope you are doing well . I've just joined this group coz I am really a 
beginner and have no idea that what I have to do !
Recently, I am  struggling to do some simple experiment with haskell language 
about parallelism and wrong answers that we can get while using a shared 
variable .
I tried to write a simple program, for example calculationg 'n=n+1' few 
times.And then I tried to do it in parallel by using 'par' and 'pseq' . The aim 
was to get the wrong answer because we have to share a variable here,and 
without using 'MVar' function we will get the wrong answer for the calculation .

I don't know how to write it in parallel in order to get a wrong answer when we 
don't use MVar,because we have a shared variable here. I read about MVars as 
well,but also I don't know how to combine MVar and Par together to get the 
program to work.

I wrote this :

module Main where f :: Int -> Int -> Int
f i n = g 1 i n where g x i n | x <= i = g (x+1) i (n+1) | otherwise = n main 
:: IO ()
main = do putStrLn "starting..." let r = f 10 5 putStrLn (show r) putStrLn 
"finished" 

I want to make to work in parallel by using 'Par'.And also use MVar for this 
simple example to work.
All of the example about MVar are a little bit complicated and I couldn't 
figure it that how can I write one,the same !

Can any one help me with this ? I want a simple example that I can feel the 
need of MVar when I run my program in parallel and while I am using a shared 
variable.

Regards;
Mozhgan 



      
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
http://www.haskell.org/pipermail/beginners/attachments/20081216/d77e37b6/attachment-0001.htm

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

Message: 4
Date: Tue, 16 Dec 2008 14:20:54 +0100
From: "Apfelmus, Heinrich" <apfel...@quantentunnel.de>
Subject: [Haskell-beginners] Re: A type level programming question
To: beginners@haskell.org
Message-ID: <gi89vb$vh...@ger.gmane.org>
Content-Type: text/plain; charset=ISO-8859-1

Levi Stephen wrote:
> Justin Bailey wrote:
>> Levi Stephen wrote:
>>>
>>> (!) :: (Pos s, Nat i, i :<: s) => FSVec s a -> i -> a
>>>
>>> I was wondering if it was possible to write a function of type:
>>>
>>> elementAt :: FSVec s a -> Int -> a
>>>
> 
> I may not have to write this function, but I'm guessing at some stage
> it's going to be necessary to convert from value level integers to
> type level. Is this a bad guess?

Yes and no. Actually, the type for  elementAt  should be

  elementAT :: FSVec s a -> Int -> Maybe a

So, you can try to fetch an element at a particular index, but it's not
guaranteed to work. In contrast,

  (!) :: (Pos s, Nat i, i :<: s) => FSVec s a -> i -> a

is guaranteed to return an element because the index is guaranteed to be
in range. The point is that  i  is usually not obtained from a value
level integer, but instead constructed from other type level integers
such that the construction vouches that it's in range.

Put differently, always using  elementAt  would be pointless, i.e. you
could dispense with type level integers entirely and use a normal list
instead.

> The type-level library provides the function reifyIntegral for this
> purpose, but the continuation is only allowed to rely on the Nat class
> constraint.
> 
> I don't know how to implement elementAt yet. FSVec provides the (!)
> function for accessing elements, but I need to satisfy the i :<: s
> class constraint before calling it.

Satisfying the  i :<: s  constraint means supplying a proof that the
integer  i  is indeed smaller than  s . Of course, if the index  i  is
not known statically, you don't have such a proof and you won't be able
to obtain one. But what you can do is to construct a different index  j
 that is guaranteed to be smaller than  s  :

  j = i `max` pred s

No matter what  i  is, j  is always going to fulfill  j :<: s. Hence,
your function can be written as

  elementAt :: FSVec s a -> Int -> Maybe a
  elementAt v i
      | 0 <= i && i < length v = reifyIntegral i at
      | otherwise              = Nothing
      where
      at i = Just $ v ! max i (pred $ lengthT v)

(Note that it may be that this code still doesn't compile, for example
because the  type-level  library maybe doesn't automatically deduce  j
:<: s  or because the type checker doesn't accept our proof for some
other reason.)


Regards,
H. Apfelmus



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

Message: 5
Date: Mon, 22 Dec 2008 08:47:29 +1030
From: "Levi Stephen" <levi.step...@gmail.com>
Subject: Re: [Haskell-beginners] Re: A type level programming question
To: "Apfelmus, Heinrich" <apfel...@quantentunnel.de>
Cc: beginners@haskell.org
Message-ID:
        <8341e4f40812211417q65165717i1fce4471e4654...@mail.gmail.com>
Content-Type: text/plain; charset=ISO-8859-1

On Tue, Dec 16, 2008 at 11:50 PM, Apfelmus, Heinrich
<apfel...@quantentunnel.de> wrote:

> Put differently, always using  elementAt  would be pointless, i.e. you
> could dispense with type level integers entirely and use a normal list
> instead.

I am finding I need this less than I thought I would. I have been
continuing on looking for alternatives and been fine so far.

>
> Satisfying the  i :<: s  constraint means supplying a proof that the
> integer  i  is indeed smaller than  s . Of course, if the index  i  is
> not known statically, you don't have such a proof and you won't be able
> to obtain one. But what you can do is to construct a different index  j
>  that is guaranteed to be smaller than  s  :
>
>  j = i `max` pred s
>
> No matter what  i  is, j  is always going to fulfill  j :<: s. Hence,
> your function can be written as
>
>  elementAt :: FSVec s a -> Int -> Maybe a
>  elementAt v i
>      | 0 <= i && i < length v = reifyIntegral i at
>      | otherwise              = Nothing
>      where
>      at i = Just $ v ! max i (pred $ lengthT v)
>
> (Note that it may be that this code still doesn't compile, for example
> because the  type-level  library maybe doesn't automatically deduce  j
> :<: s  or because the type checker doesn't accept our proof for some
> other reason.)
>

I couldn't get something along these lines to type check, but as
mentioned above I'm doing ok without it so far.

Thanks,
Levi


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

Message: 6
Date: Mon, 22 Dec 2008 13:51:15 +0000
From: Raeck Zhao <ra...@msn.com>
Subject: [Haskell-beginners] Defining a containing function on
        polymorphic     list
To: <haskell-c...@haskell.org>, <beginners@haskell.org>
Message-ID: <bay113-w1804b614efa73c4035f184bb...@phx.gbl>
Content-Type: text/plain; charset="windows-1252"





 
I am trying to define a containing function to see if a value is one
of the elements within a list which is polymorphic, but failed with the
following codes:
 > contain :: a -> [a] -> Bool

> contain x [] = False

> contain x (y:ys) = if x == y then True else contain x ys
it seems that the problem is the 'operator' == does not support a polymorphic 
check? 
Any way can solve the problem? or any alternative solution to achieve the 
purpose?
Thanks!
Raeck 
_________________________________________________________________
It’s the same Hotmail®. If by “same” you mean up to 70% faster.
http://windowslive.com/online/hotmail?ocid=TXT_TAGLM_WL_hotmail_acq_broad1_122008
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
http://www.haskell.org/pipermail/beginners/attachments/20081222/b366e3c3/attachment-0001.htm

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

Message: 7
Date: Mon, 22 Dec 2008 09:02:53 -0500
From: "Andrew Wagner" <wagner.and...@gmail.com>
Subject: [Haskell-beginners] Re: [Haskell-cafe] Defining a containing
        function on polymorphic list
To: "Raeck Zhao" <ra...@msn.com>
Cc: beginners@haskell.org, haskell-c...@haskell.org
Message-ID:
        <b8a8636e0812220602n5b10f2d3jeb95078cb6a...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"

The problem here is even slightly deeper than you might realize. For
example, what if you have a list of functions. How do you compare two
functions to each other to see if they're equal? There is no good way really
to do it! So, not only is == not completely polymorphic, but it CAN'T be.

There is a nice solution for this, however, and it's very simple:

contain :: Eq a -> [a] -> Bool
contain x [] = False
contain x (y:ys) = if x == y then True else contain x ys

The "Eq a" in the type signature says that 'a' must be a member of the 'Eq'
typeclass. That says, in turn, that 'a' must have == defined for it.
Fortunately, most types have, or can easily derive that definition. Here is
the definition of the typeclass:

class 
Eq<http://haskell.org/ghc/docs/latest/html/libraries/base/Data-Eq.html#t%3AEq>a
where(==)<http://haskell.org/ghc/docs/latest/html/libraries/base/Data-Eq.html#v%3A%3D%3D>::
a -> a ->
Bool<http://haskell.org/ghc/docs/latest/html/libraries/ghc-prim/GHC-Bool.html#t%3ABool>
(/=)<http://haskell.org/ghc/docs/latest/html/libraries/base/Data-Eq.html#v%3A%2F%3D>::
a -> a ->
Bool<http://haskell.org/ghc/docs/latest/html/libraries/ghc-prim/GHC-Bool.html#t%3ABool>
That is, for 'a' to be a member of 'Eq', it must have a == operator which
can take 2 values of that type and return a Boolean, saying whether or not
they're equal, and it must also have a definition for the /= operator, which
is "not equal". These two are also defined in terms of each other, so if you
define ==, you get /= for free, and vice versa.

That's probably more information than you needed to know, but I hope it
helps.

2008/12/22 Raeck Zhao <ra...@msn.com>

>  I am trying to define a containing function to see if a value is one of
> the elements within a list which is polymorphic, but failed with the
> following codes:
> > contain :: a -> [a] -> Bool
> > contain x [] = False
> > contain x (y:ys) = if x == y then True else contain x ys it seems that
> the problem is the 'operator' == does not support a polymorphic check?
> Any way can solve the problem? or any alternative solution to achieve the
> purpose?
> Thanks!
> Raeck
>
> ------------------------------
> It's the same Hotmail(R). If by "same" you mean up to 70% faster. Get your
> account 
> now.<http://windowslive.com/online/hotmail?ocid=TXT_TAGLM_WL_hotmail_acq_broad1_122008>
>
> _______________________________________________
> Haskell-Cafe mailing list
> haskell-c...@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
http://www.haskell.org/pipermail/beginners/attachments/20081222/58d29b34/attachment.htm

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

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


End of Beginners Digest, Vol 6, Issue 6
***************************************

Reply via email to