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. Re:  compilation error.. (Sunil S Nandihalli)
   2.  pattern x:xs (Luca Ciciriello)
   3. Re:  Why ShowS? (Christian Maeder)
   4. Re:  Why ShowS? (Yitzchak Gale)
   5. Re:  Cannot install cairo with cabal... (Dave Bayer)
   6. Re:  pattern x:xs (Brandon Allbery)
   7. Re:  pattern x:xs (David Virebayre)


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

Message: 1
Date: Thu, 11 Aug 2011 17:39:09 +0530
From: Sunil S Nandihalli <[email protected]>
Subject: Re: [Haskell-beginners] compilation error..
To: Brandon Allbery <[email protected]>
Cc: [email protected]
Message-ID:
        <cap0fd73ed51nqmcxr_qodekpp7z19hq2o+pl_wq6dx643rl...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

aah .. Thanks a lot Brandon, you were right .. I was getting a Int and was
destructuring for tuple.. Thanks again
Sunil.

On Thu, Aug 11, 2011 at 5:33 PM, Brandon Allbery <[email protected]>wrote:

> On Thu, Aug 11, 2011 at 07:43, Sunil S Nandihalli <
> [email protected]> wrote:
>
>> Hello everybody,
>>  when I compile the file
>>
>> https://github.com/sunilnandihalli/is2/blob/master/main.hs
>>
>> I get
>> main.hs:28:64:
>>     Could not deduce (Enum (a, t0))
>>       arising from the arithmetic sequence `0 .. '
>>     from the context (Integral a)
>>       bound by the type signature for
>>                  plotAsString :: Integral a => [(a, a)] -> (a, a) ->
>> String
>>       at main.hs:(26,1)-(38,41)
>>     Possible fix:
>>       add (Enum (a, t0)) to the context of
>>         the type signature for
>>           plotAsString :: Integral a => [(a, a)] -> (a, a) -> String
>>       or add an instance declaration for (Enum (a, t0))
>>     In the second argument of `zip', namely `[0 .. ]'
>>     In the first argument of `M.fromList', namely `(zip locs [0 .. ])'
>>     In the expression: M.fromList (zip locs [0 .. ])
>>
>
> The weird error is because Haskell is defined to promote integer literals
> to instances of Integral, then applying further an instance of Enum; but the
> actual type it's expecting is a tuple because you're using (Just (id,_)) on
> line 34 as the result of (M.lookup).  Were you perhaps expecting
> (M.lookup) to return a tuple of the key and value?
>
> (Also, in light of your previous message, you'll find things compile more
> easily if you learn the correct types and behaviors of standard Haskell
> functions instead of making assumptions possibly based on the behavior of
> some other language.)
>
> --
> brandon s allbery                                      [email protected]
> wandering unix systems administrator (available)     (412) 475-9364 vm/sms
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20110811/c9e66540/attachment-0001.htm>

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

Message: 2
Date: Thu, 11 Aug 2011 15:37:17 +0200
From: Luca Ciciriello <[email protected]>
Subject: [Haskell-beginners] pattern x:xs
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset="windows-1252"

Is it possible to use the pattern (x:xs) using a parallel array [::]?

In other words, is there a way to parallelize the code:

myfunc :: [:String:] -> [String]
myfunc [::] = []
myfunc (x:xs) = ?

if I try to compile this I get the error:

Couldn't match expected type `[:String:]'
                with actual type `[t0]'
                In the pattern: x : xs

Is there a syntax in order to use the (x:xs) pattern?

Thanks in advance

Luca.


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

Message: 3
Date: Thu, 11 Aug 2011 17:24:59 +0200
From: Christian Maeder <[email protected]>
Subject: Re: [Haskell-beginners] Why ShowS?
To: [email protected]
Cc: Haskell Beginners <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed

Am 11.08.2011 11:13, schrieb Yitzchak Gale:
> Here is a simple example of how to use ShowS:
>
> showPerson :: String ->  Int ->  Int ->  String
> showPerson name age shoeSize =
>    concat [ "Name: ", name, ", Age: ", show age,
>    ", Shoe size: ", show shoeSize]
> ...
> putStrLn $ showPerson name age shoe
>
> becomes, in the ShowS style:
>
> showsPerson :: String ->  Int ->  Int ->  ShowS
> showsPerson name age shoeSize =
>    ("Name: " ++) . (name ++) . (", Age: " ++) . shows age .
>    (", Shoe size: " ++) . shows shoeSize
> ...
> putStrLn $ showsPerson name age shoe ""

I think, this examples shows, why ShowS is rarely used!

It would even be longer if you used "showString" instead of these (ugly) 
sections with ++ (instead of using ++ directly).

I don't think, there's a performance issue, either. (++ is 
right-associative).

Creating a (better formatted) list of strings and then using "concat", 
"unwords", "unlines" or "intercalate ", " is quite a good choice.

Cheers Christian

>
> Regards,
> Yitz
>



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

Message: 4
Date: Thu, 11 Aug 2011 20:25:39 +0300
From: Yitzchak Gale <[email protected]>
Subject: Re: [Haskell-beginners] Why ShowS?
To: Christian Maeder <[email protected]>
Cc: Haskell Beginners <[email protected]>
Message-ID:
        <caorualaaek+wcairctqx2-kjxgpn_d875l4eusoyknho1+y...@mail.gmail.com>
Content-Type: text/plain; charset=ISO-8859-1

I wrote:
>> Here is a simple example of how to use ShowS...

Christian Maeder wrote:
> I think, this examples shows, why ShowS is rarely used!

I understand your feelings. The sections of ++ do look awkward
on the surface, though in practice it's not really much of an
issue.

> It would even be longer if you used "showString" instead of
> these (ugly) sections with ++ (instead of using ++ directly).

Yes. That's why I used the sections in my examples,
instead of the Prelude function "showString".

Most other function-composition-style pretty-printing
libraries using something shorter than "showString", like
"text", to replace the ++ sections. Then it comes out the
same length. You could use something even shorter.

But saving a few keystrokes is not the point. The point is
writing the expression as a compositional pipeline, which is
conceptually nice, and more or less the same complexity in
syntax.

> I don't think, there's a performance issue, either. (++ is
> right-associative).

I think you're right. That was more of an issue for early
compilers.

> Creating a (better formatted) list of strings and then using "concat",
> "unwords", "unlines" or "intercalate ", " is quite a good choice.

Indeed, it's fine, and it's the most popular.

Once you realize the beauty and power of the compositional
combinator approach in general, though, using that approach
also for rendering becomes an attractive alternative. Especially
in situations where you might want to insert other
combinators into the pipeline.

Anyway, I think that's a more complete answer to Christopher's
original question about ShowS.

Thanks,
Yitz



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

Message: 5
Date: Thu, 11 Aug 2011 15:40:28 -0700
From: Dave Bayer <[email protected]>
Subject: Re: [Haskell-beginners] Cannot install cairo with cabal...
To: Haskell-beginners <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii

Just to get this on the record (I found this message while googling [PackageDB] 
for a similar error):

[1] One needs a dash,

        cabal install --ghc-option=-DCABAL_VERSION_MINOR=10 cairo

[2] It's irrelevant what the "correct answer" is as to the version of Cabal; 
one may want the wrong answer. The Setup.hs in an older package may not have 
correctly predicted future development. Developers could use "micro" versions 
to keep variants current, but they tend not to do so.

One wants the branch of Setup.hs code that picks the right variant between 
[PackageDB] and PackageDB, so the install gets past hanging on this issue. One 
needs to look at the code. In my case, I needed

        cabal install --ghc-option=-DCABAL_VERSION_MINOR=6 glib-0.11.2

and I could only figure that out by looking at the branching code in 
Gtk2HsSetup.hs; the two choices in that file were 6 and 8. 6 works, 8 doesn't, 
I'm actually on 10, go figure.

Several days of part-time yak shaving in, I managed to get gtk+ up on OS X 
using fink (not manually or using MacPorts) but it's an older version. The 
current glib assumes it can make a call to g_mount_get_default_location, which 
is described online but not in the fink version of gio. This earlier glib 
doesn't assume it can make a call to g_mount_get_default_location. Alas, but 
this earlier glib triggers the [PackageDB] versus PackageDB Cabal bug, claimed 
to be fixed on various tickets. And that's 0.4% of the yak shaving I've been 
doing.

In an ideal world there'd be a glib-0.11.3 that works with contemporary 
versions of cabal without this hack, but doesn't assume recent advances in gtk+ 
such as the g_mount_get_default_location call. That's what micro versions are 
for.

On Jul 7, 2011, at 3:38 AM, Jack Henahan wrote:

> That looks like it might be a bug in the source. What it says, in short, is 
> that it expects that sixth argument in (i.e., registerPackage _ _ _ _ _ O) to 
> be a PackageDBStack, but instead it's a PackageDB.
> 
> The lines around where the error occurs are
> 
>    #if CABAL_VERSION_CHECK(1,10,0)
>                                        installedPkgInfo pkg lbi inplace 
> [packageDb]
>    #else
>                                        installedPkgInfo pkg lbi inplace 
> packageDb
>    #endif
> 
> So it seems that it can't infer your cabal's minor version, so it drops into 
> the else. Do you get any different result when you call `cabal install 
> --ghc-option=DCABAL_VERSION_MINOR=10 cairo`?



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

Message: 6
Date: Thu, 11 Aug 2011 19:49:34 -0400
From: Brandon Allbery <[email protected]>
Subject: Re: [Haskell-beginners] pattern x:xs
To: Luca Ciciriello <[email protected]>
Cc: [email protected]
Message-ID:
        <CAKFCL4U6XH=ZKpCMkKe8VhFDZ1gxuyAz0RnpT3zNM3WgALM=f...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

On Thu, Aug 11, 2011 at 09:37, Luca Ciciriello
<[email protected]>wrote:

> Is it possible to use the pattern (x:xs) using a parallel array [::]?
>

If it's there at all, I would expect the syntax to be as (:) is to [,]:
 (:x:xs:).  That said, normal arrays have no such syntax, so parallel arrays
may not either.  (Then again, normal arrays don't even have an equivalent of
[: :]; you have to marshal/demarshal from a list.)

-- 
brandon s allbery                                      [email protected]
wandering unix systems administrator (available)     (412) 475-9364 vm/sms
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20110811/aba0b627/attachment-0001.htm>

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

Message: 7
Date: Fri, 12 Aug 2011 08:50:32 +0200
From: David Virebayre <[email protected]>
Subject: Re: [Haskell-beginners] pattern x:xs
To: Luca Ciciriello <[email protected]>
Cc: [email protected]
Message-ID:
        <cam_wfvstb6hjzkxd3afy1xiutftcs6uuxcgtkto+kfbamod...@mail.gmail.com>
Content-Type: text/plain; charset=UTF-8

2011/8/11 Luca Ciciriello <[email protected]>:
> Is it possible to use the pattern (x:xs) using a parallel array [::]?

I don't know that you can do it this way but maybe the GHC extension
view patterns can do something close enough.

David.



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

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


End of Beginners Digest, Vol 38, Issue 27
*****************************************

Reply via email to