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:  How to compile stub? (Ozgur Akgun)
   2. Re:  cabal and dependencies (Manfred Lotz)
   3. Re:  cabal and dependencies (Andres Loeh)
   4.  'case of' question (Manfred Lotz)
   5.  Getting Stuff out of IO Handles (Raphael P?bst)
   6. Re:  'case of' question (Brandon Allbery)
   7. Re:  'case of' question (Brandon Allbery)
   8.  Would you shed light on "undefined values"       please?
      (Costello, Roger L.)
   9. Re:  Getting Stuff out of IO Handles (Arlen Cuss)


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

Message: 1
Date: Thu, 23 Jun 2011 16:08:29 +0300
From: Ozgur Akgun <[email protected]>
Subject: Re: [Haskell-beginners] How to compile stub?
To: Zhi-Qiang Lei <[email protected]>
Cc: Haskell Beginer <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset="utf-8"

Hi.

You refer to many types & data constructors, which are neither defined nor
imported.

On 22 June 2011 11:54, Zhi-Qiang Lei <[email protected]> wrote:

> import SimpleJSON
>

Can we see the contents of this file?

Ozgur
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20110623/a7215d5d/attachment-0001.htm>

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

Message: 2
Date: Thu, 23 Jun 2011 16:14:34 +0200
From: Manfred Lotz <[email protected]>
Subject: Re: [Haskell-beginners] cabal and dependencies
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=US-ASCII

On Thu, 23 Jun 2011 11:46:12 +0200
Andres Loeh <[email protected]> wrote:

> Hi Manfred.
> 
> > I did 'ghc-pkg check' which showed nothing. Fine!
> >
> > Then I did 'cabal install gitit' and after successfully installing
> > gitit I ran 'ghc-pkg check' again and got:
> 
> [lots of broken packages deleted]
> 
> Yes. That can happen with current cabal-install.
> 
> > Why is this happening?
> 
> The dependency resolution algorithm will try to make a consistent
> install plan that allows gitit to be run. However, in order to achieve
> that, it may decide that it's necessary to reinstall some existing
> packages in a new configuration (with other dependency or flag
> settings). Such reinstalls will then overwrite the previous package in
> the store, and if that previous package was depended on by something
> else, these other things will break.
> 
> While ghc-pkg currently allows both foo-1.0 and foo-2.0 to be in the
> store at the same time, it doesn't allow two different configurations
> of foo-2.0 in the store at the same time.
> 
> > Could I prevent it somehow?
> 
> Currently, you can only discover the danger of this happening in
> advance: You can run "cabal install --dry-run -v gitit", and then
> you'll get an annotated install plan printed out. If you notice lines
> like
> 
> HTTP-4000.1.1 (reinstall) changes: network-2.3.0.2 -> 2.2.1.10
> 
> then you are in danger. If you only see lines that say "(new package)"
> or "(new version)", you're safe.
> 
> In the new dependency resolver I'm currently implementing for Cabal,
> which you can preview at
> 
>   http://darcs.haskell.org/cabal-branches/cabal-modular-solver/
> 
> there will be an option "--avoid-reinstalls" that tries to avoid
> reinstalls (but perhaps at the cost of selecting older versions of
> certain packages to avoid them). Also, the next release of Cabal will
> probably add a warning if an install plan contains reinstalls.
> 
> The proper solution would be to lift the limitation in the GHC package
> store and allow arbitrarily many variants of packages to coexist
> peacefully, so that even a "reinstall" won't have to remove an old
> version. I hope we're getting around to implement this sooner or
> later.
> 
> Cheers,
>   Andres
> 

Thanks for explaining it.


I had another issue with optional syntax highlighting support in gitit.
The gitit web site says that if it available in pandoc then it is
available in gitit too.

Then the recommendation is:
"To install gitit with highlighting support, first ensure that pandoc
is compiled with highlighting support, then install gitit as above:

cabal install pandoc -fhighlighting --reinstall
cabal install gitit"

If I do this it doesn't work because when installing gitit pandoc will
be rebuilt again.

I did: cabal install git pandoc -fhighlighting --reinstall

which helped.

I guess this fits also in the explanations you gave me.




-- 
Manfred





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

Message: 3
Date: Thu, 23 Jun 2011 16:23:03 +0200
From: Andres Loeh <[email protected]>
Subject: Re: [Haskell-beginners] cabal and dependencies
To: Manfred Lotz <[email protected]>
Cc: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1

Hi again.

> I had another issue with optional syntax highlighting support in gitit.
> The gitit web site says that if it available in pandoc then it is
> available in gitit too.
>
> Then the recommendation is:
> "To install gitit with highlighting support, first ensure that pandoc
> is compiled with highlighting support, then install gitit as above:
>
> cabal install pandoc -fhighlighting --reinstall
> cabal install gitit"
>
> If I do this it doesn't work because when installing gitit pandoc will
> be rebuilt again.
>
> I did: cabal install git pandoc -fhighlighting --reinstall
>
> which helped.
>
> I guess this fits also in the explanations you gave me.

Yes, it's somewhat similar, and you did the right thing. If you
request pandoc in isolation, it will be built against the versions of
its dependencies you already have installed, or, if you don't, against
the latest versions of these dependencies.

However, gitit introduces additional constraints, and the version of
pandoc you get when you ask for it individually currently doesn't meet
these constraints. By putting them both as targets on a single command
line, you get cabal to make a consistent install plan for both
packages.

Cheers,
  Andres



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

Message: 4
Date: Thu, 23 Jun 2011 17:02:31 +0200
From: Manfred Lotz <[email protected]>
Subject: [Haskell-beginners] 'case of' question
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=US-ASCII

Hi there,
Let's say I have something like this (it is an artificial example just
for illustration):

case x of
 1 -> doThis
 5 -> doThis
 76 -> doThis
 112 -> doThat
 21 -> doThat
 _ -> doOtherwise


I would like to have something like this (which is illegal)

case x of
 1 | 5 | 76  -> doThis
 112 | 21 -> doThat
  _ -> doOtherwise


Is something like this possible to do? 


The only idea I got is:

processX x 
  | x `elem` [ 1, 5, 76 ] = doThis
  | x `elem` [ 112, 21 ] = doThat
  | otherwise = doOtherwise



-- 
Manfred





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

Message: 5
Date: Thu, 23 Jun 2011 17:23:38 +0200
From: Raphael P?bst <[email protected]>
Subject: [Haskell-beginners] Getting Stuff out of IO Handles
To: beginners <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1

Hey everyone!
This is probably a stupid question, but is there a way to get stuff
out of a IO handle?
If I do something with an IO handle, reading in data from a file for
example and then do something with the data, is there a way to get the
results out of the handle, comparable to the return in a do block?
Or do all operations on the data have to happen inside the handle?
Thanks

Raf



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

Message: 6
Date: Thu, 23 Jun 2011 11:29:40 -0400
From: Brandon Allbery <[email protected]>
Subject: Re: [Haskell-beginners] 'case of' question
To: Manfred Lotz <[email protected]>
Cc: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset="utf-8"

On Thu, Jun 23, 2011 at 11:02, Manfred Lotz <[email protected]> wrote:

> The only idea I got is:
>
> processX x
>  | x `elem` [ 1, 5, 76 ] = doThis
>  | x `elem` [ 112, 21 ] = doThat
>  | otherwise = doOtherwise
>

That's the correct way to do it.  The trick is to remember that the above is
really a "case of":

> case x of
>   _ | x `elem` [1, 5, 76] -> doThis
>     | x `elem

-- 
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/20110623/d59715b8/attachment-0001.htm>

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

Message: 7
Date: Thu, 23 Jun 2011 11:32:50 -0400
From: Brandon Allbery <[email protected]>
Subject: Re: [Haskell-beginners] 'case of' question
To: Manfred Lotz <[email protected]>
Cc: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=UTF-8

On Thu, Jun 23, 2011 at 11:29, Brandon Allbery <[email protected]> wrote:
> On Thu, Jun 23, 2011 at 11:02, Manfred Lotz <[email protected]> wrote:
>>
>> The only idea I got is:
>>
>> processX x
>> ?| x `elem` [ 1, 5, 76 ] = doThis
>> ?| x `elem` [ 112, 21 ] = doThat
>> ?| otherwise = doOtherwise
>
> That's the correct way to do it.? The trick is to remember that the above is 
> really a "case of":

(with the cat off my arm so I'm not whacking the wrong keys...)

> case x of
>   _ | x `elem` [1, 5, 76] -> doThis
>     | x `elem` [112, 21] -> doThat
>     | otherwise -> doSomethingElse

--
brandon s allbery ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? [email protected]
wandering unix systems administrator (available) ? ? (412) 475-9364 vm/sms



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

Message: 8
Date: Thu, 23 Jun 2011 18:35:19 -0400
From: "Costello, Roger L." <[email protected]>
Subject: [Haskell-beginners] Would you shed light on "undefined
        values" please?
To: "[email protected]" <[email protected]>
Message-ID:
        <[email protected]>
Content-Type: text/plain; charset="us-ascii"

Hi Folks,

In this book [1] the author defines the term "bottom":

   In order that we can say that, without exception, every
   syntactically well-formed expression denotes a value,
   it is convenient to introduce a special symbol (upside
   down T), pronounced 'bottom', to stand for the undefined
   value of a particular type. In particular, the value of
   infinity is the undefined value (bottom) of type Integer,
   and 1/0 is the undefined value (bottom) of type Float.
   Hence we can assert that 1/0 = bottom.

He defines infinity as this:

    infinity :: Integer
    infinity = infinity + 1

The author says this when discussing the Bool datatype:

    It follows that there are not two but three Boolean
    values, namely False, True, and bottom. In fact, every
    datatype declaration introduces an extra anonymous
    value, the undefined value of the datatype.

What is the undefined value (bottom) of type Bool?

What is the undefined value (bottom) of type String?

If I create my own datatype:

data MyBool = F | T

What is the undefined value (bottom) of type MyBool?

I am not clear why "bottom" is an important concept. Would you explain please?

/Roger

[1] Introduction to Functional Programming using Haskell by Richard Bird



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

Message: 9
Date: Fri, 24 Jun 2011 08:58:04 +1000
From: Arlen Cuss <[email protected]>
Subject: Re: [Haskell-beginners] Getting Stuff out of IO Handles
To: Raphael P?bst <[email protected]>
Cc: beginners <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1

On 24/06/2011 1:23 AM, Raphael P?bst wrote:
> Hey everyone!
> This is probably a stupid question,

No such thing. :)

> but is there a way to get stuff out of a IO handle?

You have to bind it in the IO monad. This means, for example, if you
have a handle called `h', in a do block:

  line <- hGetLine h

This is syntactic sugar for hGetLine h >>= (\line -> ...), where the
`...' is whatever follows in the do block.

> If I do something with an IO handle, reading in data from a file for
> example and then do something with the data, is there a way to get the
> results out of the handle, comparable to the return in a do block?

return is actually the opposite(!) -- it puts something *in* the monad.
I think you may have handles and the IO monad itself confused, but if
you'd like to post some sample code, we could show you how to achieve
what you want, and explain it more fully. :)

Here are some small examples of using handles and IO:

-- these are provided by System.IO:
stdin :: Handle
stdout :: Handle
hGetLine :: Handle -> IO String
hPutStrLn :: Handle -> String -> IO ()

-- from Control.Monad:
forever :: Monad m => m a -> m b

-- an example of using a handle:
copyLine :: Handle -> Handle -> IO ()
copyLine inh outh = do
  line <- hGetLine inh
  hPutStrLn outh line

-- The above 'do' block can be simplified to:
--   hGetLine inh >>= (\line -> hPutStrLn outh line)
-- and then to:
--   hGetLine inh >>= hPutStrLn outh

main :: IO ()
main = forever $ copyLine stdin stdout

.. it's a bit verbose, but perhaps helpful. If it's returning the result
of an op on a handle, it's much the same:

copyLineAndReturn :: Handle -> Handle -> IO String
copyLineAndReturn inh outh = do
  line <- hGetLine inh
  hPutStrLn outh line
  return line

-- hGetLine inh >>= (\line -> hPutStrLn outh line >> return line)

> Thanks
> 
> Raf

Cheers,

Arlen



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

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


End of Beginners Digest, Vol 36, Issue 58
*****************************************

Reply via email to