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.  type def messes up (prad)
   2. Re:  type def messes up (Daniel Fischer)
   3. Re:  type def messes up (Daniel Fischer)
   4.  Re: type def messes up (prad)
   5. Re:  Re: type def messes up (Daniel Fischer)
   6.  System.Process.createProcess does not terminate (John Obbele)
   7. Re:  System.Process.createProcess does not        terminate
      (Brandon S Allbery KF8NH)
   8. Re:  Category Theory (Paul Higham)


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

Message: 1
Date: Sat, 26 Jun 2010 12:27:20 -0700
From: prad <[email protected]>
Subject: [Haskell-beginners] type def messes up
To: haskellbeginners <[email protected]>
Message-ID: <20100626122720.3dc0f...@gom>
Content-Type: text/plain; charset=US-ASCII

sometimes i have copied a typedef from a tutorial or demo and get
errors. i take the typedef out and the program runs fine.

i don't think the problem lies with the person creating the typedef
because they are very experienced.

is it possible that the matter has to do with the interpreter eg hugs
vs ghci and such?
or possibly an update of the syntax over time?

for instance, i'm going through rex page's "two dozen short lessons in
haskell" from uni of oklahoma. they use hugs and the error message for 

reverse 'x'

is completely different from what i get using ghci.

-- 
In friendship,
prad

                                      ... with you on your journey
Towards Freedom
http://www.towardsfreedom.com (website)
Information, Inspiration, Imagination - truly a site for soaring I's


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

Message: 2
Date: Sat, 26 Jun 2010 21:49:40 +0200
From: Daniel Fischer <[email protected]>
Subject: Re: [Haskell-beginners] type def messes up
To: [email protected]
Cc: prad <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain;  charset="iso-8859-1"

On Saturday 26 June 2010 21:27:20, prad wrote:
> sometimes i have copied a typedef from a tutorial or demo and get
> errors. i take the typedef out and the program runs fine.

Then ask ghci what the type is, e.g.

Prelude> :t reverse
reverse :: [a] -> [a]

>
> i don't think the problem lies with the person creating the typedef
> because they are very experienced.

Maybe, maybe not.

>
> is it possible that the matter has to do with the interpreter eg hugs
> vs ghci and such?
> or possibly an update of the syntax over time?

Unlikely for simple functions. For advanced stuff that requires extensions, 
that can happen.

>
> for instance, i'm going through rex page's "two dozen short lessons in
> haskell" from uni of oklahoma. they use hugs and the error message for
>
> reverse 'x'
>
> is completely different from what i get using ghci.

ghc and hugs give very different error messages, but it boils down to the 
same:

hugs:
Hugs> reverse 'x'
ERROR - Type error in application
*** Expression     : reverse 'x'
*** Term           : 'x'
*** Type           : Char
*** Does not match : [a]

ghci:
Prelude> reverse 'x'

<interactive>:1:8:
    Couldn't match expected type `[a]' against inferred type `Char'
    In the first argument of `reverse', namely 'x'
    In the expression: reverse 'x'
    In the definition of `it': it = reverse 'x'

Both say that you passed an argument of type Char to a function which works 
on lists (of any type).




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

Message: 3
Date: Sat, 26 Jun 2010 22:18:35 +0200
From: Daniel Fischer <[email protected]>
Subject: Re: [Haskell-beginners] type def messes up
To: [email protected]
Cc: prad <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain;  charset="iso-8859-1"

On Saturday 26 June 2010 21:27:20, prad wrote:
> for instance, i'm going through rex page's "two dozen short lessons in
> haskell" from uni of oklahoma.

Wow, that's even pre-Haskell98.
It refers to the Haskell-1.3 report.
There have been many changes in the language since then.
It might have become pretty unusable by now, perhaps you should try another 
tutorial (YAHT [although that is quite old too, many of the function it 
says are in the Prelude aren't anymore] or LYAH for example).


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

Message: 4
Date: Sat, 26 Jun 2010 15:35:27 -0700
From: prad <[email protected]>
Subject: [Haskell-beginners] Re: type def messes up
To: [email protected]
Message-ID: <20100626153527.57306...@gom>
Content-Type: text/plain; charset=US-ASCII

On Sat, 26 Jun 2010 22:18:35 +0200
Daniel Fischer <[email protected]> wrote:

> It refers to the Haskell-1.3 report.
> There have been many changes in the language since then.
>
ok thx for the warning.
i'm starting to notice some issues.

also thx for the tips in your other post daniel.

here's a specific item i was referring to:

ndmPapers :: IO ()
ndmPapers = do
        tags <- fmap parseTags $ openURL
"http://community.haskell.org/~ndm/downloads/"; let papers = map f $
sections (~== "<li class=paper>") tags putStr $ unlines papers
    where
        f :: [Tag] -> String
        f xs = fromTagText (xs !! 2)
http://community.haskell.org/~ndm/darcs/tagsoup/tagsoup.htm
at the bottom of the page: my papers (neil mitchell who wrote tagsoup
for haskell)

with the 
f :: [Tag] -> String
left in ghci croaks:

======
TagSoup.hs:66:14:
    `Tag' is not applied to enough type arguments
    Expected kind `*', but `Tag' has kind `* -> *'
    In the type signature for `f': f :: [Tag] -> String
    In the definition of `ndmPapers':
        ndmPapers = do { tags <- fmap parseTags
                               $ openURL
"http://community.haskell.org/~ndm/downloads/";; let papers = ...;
                           putStr $ unlines papers }
                  where
                      f :: [Tag] -> String
                      f xs = fromTagText (xs !! 2)
Failed, modules loaded: none.
======
(i'm guessing that Tag is some type defined in Text.HTML.TagSoup)

however, the program runs fine if i comment out the type def.

so i'm curious as to why this is so.

i can't do a :t on f getting a 'not in scope' error, i guess because it
is part of ndmPapers, but that seems strange to me.

-- 
In friendship,
prad

                                      ... with you on your journey
Towards Freedom
http://www.towardsfreedom.com (website)
Information, Inspiration, Imagination - truly a site for soaring I's


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

Message: 5
Date: Sun, 27 Jun 2010 00:53:18 +0200
From: Daniel Fischer <[email protected]>
Subject: Re: [Haskell-beginners] Re: type def messes up
To: [email protected]
Cc: prad <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain;  charset="iso-8859-1"

On Sunday 27 June 2010 00:35:27, prad wrote:
>
> with the
> f :: [Tag] -> String
> left in ghci croaks:
>
> ======
> TagSoup.hs:66:14:
>     `Tag' is not applied to enough type arguments
>     Expected kind `*', but `Tag' has kind `* -> *'
>     In the type signature for `f': f :: [Tag] -> String
>     In the definition of `ndmPapers':
>         ndmPapers = do { tags <- fmap parseTags
>                                $ openURL
> "http://community.haskell.org/~ndm/downloads/";; let papers = ...;
>                            putStr $ unlines papers }
>                   where
>                       f :: [Tag] -> String
>                       f xs = fromTagText (xs !! 2)
> Failed, modules loaded: none.
> ======
> (i'm guessing that Tag is some type defined in Text.HTML.TagSoup)
>
> however, the program runs fine if i comment out the type def.
>
> so i'm curious as to why this is so.

Neil changed the kind of Tag in tagsoup-0.8, until version 0.6, it was

data Tag
    = TagOpen String [Attribute]
    | TagClose String
    | TagText String
    | TagComment String
    | TagWarning String
    | TagPosition !Row !Column

and it became

data Tag str
    = TagOpen str [Attribute str]
    | TagClose str
    ...

in 0.8, I think the reason was to allow the use of ByteStrings and 
Data.Text in addition to plain String.

It would also work with

f :: [Tag String] -> String

>
> i can't do a :t on f getting a 'not in scope' error, i guess because it
> is part of ndmPapers, but that seems strange to me.

It would be very nice if one could query the type of local definitions.



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

Message: 6
Date: Sun, 27 Jun 2010 00:57:59 +0200
From: John Obbele <[email protected]>
Subject: [Haskell-beginners] System.Process.createProcess does not
        terminate
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset="us-ascii"

Hello everyones !

I was playing with some test frameworks recently and came across
what looks like a pseudo-fork bomb.

After digging things a little, it seems I am messing with the
System.Process.createProcess function : none of my spawned
process terminates and eventually my OS freezes. (trivia: well
now, I know that Fedora cannot handle more than 1100 processes on
my cheap laptop ^^)

I've attached a small haskell file which can easily reproduces my
problem. If you, carefully, run it from the GHCi prompt while
monitoring your pool of processes, you will probably see a
hundred of zombie processes appearing.

Has anyone got some clues on what's wrong with my function ? Is
it related to some strange lazy behavior or should I simply
manage each spawned process myself and terminate it when needed ?

regards,
/John

P.S.: speaking of test frameworks, I am desperate to find good
examples or documentations on how to use QuickCheck2. Where could
I get such resources ?
-------------- next part --------------
-- Be Careful when running this file
-- spawned processes could hang up your system

import System.Process
import System.IO

tr input = do 
    let (cmd, args) = ("tr", ["a-z", "A-Z"])
    let process = (proc cmd args){ std_in = CreatePipe
                                 , std_out = CreatePipe
                                 , close_fds = True }
    (Just hin, Just hout, _, _) <- createProcess process
    -- inject data
    hPutStr hin input
    hClose hin
    -- return (IO String)
    hGetContents hout

tr' input = do
    let process = (proc "tr" ["a-z", "A-Z"]){ std_in = CreatePipe
                                            , std_out = CreatePipe 
                                            , close_fds = True }
    (Just hin, Just hout, _, _) <- createProcess process
    -- inject data
    hPutStr hin input
    hClose hin
    -- return (IO String)
    putStr =<< hGetContents hout
    hClose hout

test00 = mapM_ (\_ -> tr "Homebrew fork-bomb\n" >>= putStr) [0..50]
test01 = mapM_ (\_ -> tr' "Homebrew fork-bomb\n") [0..50]

main = test00 >> test01 >> wait
  where wait = do putStrLn "Press any key to quit"
                  input <- getLine
                  putStrLn (">>" ++ input)

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

Message: 7
Date: Sat, 26 Jun 2010 20:59:01 -0400
From: Brandon S Allbery KF8NH <[email protected]>
Subject: Re: [Haskell-beginners] System.Process.createProcess does not
        terminate
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=UTF-8

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 6/26/10 18:57 , John Obbele wrote:
> After digging things a little, it seems I am messing with the
> System.Process.createProcess function : none of my spawned
> process terminates and eventually my OS freezes. (trivia: well
> now, I know that Fedora cannot handle more than 1100 processes on
> my cheap laptop ^^)
> 
> I've attached a small haskell file which can easily reproduces my
> problem. If you, carefully, run it from the GHCi prompt while
> monitoring your pool of processes, you will probably see a
> hundred of zombie processes appearing.

You need to reap zombies manually; take a look at
System.Process.waitForProcess.  (On POSIX-ish systems, including Linux, you
can use the signal handling functions to auto-reap; on Linux simply setting
SIGCHLD to SIG_IGN is good enough, but other systems (*BSD, OSX) require you
to also set the SA_NOCLDWAIT flag and for portability you should include it.
 (Which, I note, doesn't seem to be supported in System.Posix.Signals.  O
Haskell gods:  Bug?)

- -- 
brandon s. allbery     [linux,solaris,freebsd,perl]      [email protected]
system administrator  [openafs,heimdal,too many hats]  [email protected]
electrical and computer engineering, carnegie mellon university      KF8NH
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (Darwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAkwmokUACgkQIn7hlCsL25W2tACfaWaPdUI3h08Ie8CgRd30PaXF
3bMAn1SckfRXKygSS/FhpOL5Vs6/wwjk
=rkBx
-----END PGP SIGNATURE-----


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

Message: 8
Date: Sat, 26 Jun 2010 18:51:48 -0700
From: Paul Higham <[email protected]>
Subject: Re: [Haskell-beginners] Category Theory
To: Matt Andrew <[email protected]>
Cc: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes

I am also on a similar quest.  Specifically, I want to understand the   
connection between the notion of monad as defined in category theory  
and the application of this concept to functional programming.  Even  
more specifically I want to grok how monads provide an elegant  
solution to the problem of requiring side effects in a programming  
style that expressly forbids them.  But anyway with my very limited  
understanding of these things I'll take a crack at some of your  
questions below.

::paul

On Jun 24, 2010, at 3:33 AM, Matt Andrew wrote:

> Hi all,
>
> I have spend some time over the last couple of days trying to get my  
> head around category theory, in order to understand concepts like  
> monads a little better, in order to understand Haskell a little  
> better =) I have grasped, at least to a degree, the basic concepts  
> of 'category,' 'functor' and 'natural transformation' but I am still  
> fuzzy on a few specifics and had a couple of questions. I'm doing  
> this for self-study and have no one to ask these questions of and so  
> thought I'd ask them here.
>
> My first question is this: where are functors understood to 'live,'  
> or exist? They operate on categories, are they therefore understood  
> to exist outside of the categories they operate on? (I understand  
> that functors can form a category themselves, but I'm asking this  
> question in relation to the categories they operate on. Are they  
> inside or outside of them?)

In category theory a functor exists between two categories in much the  
same way that a function exists between two sets.  If functors  
belonged to a category (as in 'inside' the category) then which  
category would they belong to?  For example, one of my favourite  
functors is the forgetful functor (I can really identify with that  
property :) ) that leaves behind some of the structure of the source  
object when it picks up the target.  Think of a vector space  
forgetting its addition and scalar multiplication and becoming just a  
set.  Such a functor does not rightly 'belong' to the category of  
vector spaces because its purpose is to destroy what it means to be a  
vector space, and it doesn't belong to the category of sets because  
if  you are a set why would you be expected to know what it was you  
forgot in order to get there when you were already there all along?

>
> In other words when I define a functor in Haskell, are the pair of  
> functions 'fmap,' and whatever unary type constructor is defined  
> along with it, then part of the morphisms of the Haskell category?  
> Or are they outside of the Haskell category (where the Haskell  
> category I've seen defined in the articles I've read is one where  
> its objects are types and its morphisms functions on those types)?
>
> This leads me to my next question. It seems that all functors in  
> Haskell (or at least all members of the functor typeclass) are  
> covalent endofunctors. Does this mean that whenever a new functor is  
> defined in Haskell, that the Haskell category (H) grows to  
> accomodate the effects of that functor? In other words, for any  
> covalent endofunctor F : H -> H, do H's morphisms then grow to  
> include F(f) and objects to include F(a), where a is any object in H  
> and f is any morphism in H?

Again in classical category theory all the objects and morphisms exist  
independently of any newly identified functor, so from that view the  
answer is 'no', for F to be a functor on H then for all objects a and  
morphisms f in H, F(a) and F(f) must already exist in H or the functor  
could not have been defined.  However, the putative existence of an  
object in the Haskell category does not mean that there is an  
implementation of it.  Note that there are infinitely many integers  
that have never been written down, but mathematicians still believe  
they exist!

> I have been working off the assumption that the answer to my last  
> question is 'yes.' The reason for this is natural transformations.  
> Where functors seem to be able to be 'outside' of the categories  
> they operate on (whether they are in fact 'outside' or not is my  
> first question), natural transformations appear to have to be  
> 'inside.' My understanding of the theory is that a natural  
> transformation is a collection of morphisms in the target category  
> of two parallel functors (where such morphisms operate on the  
> functors and meet some specific properties). Surely the only way  
> such a collection of morphisms would make sense would be if the  
> objects they map to/from (i.e. the structures imposed by the two  
> functors) were part of that category also?

Is it possible that there is some confusion coming from the fact that  
you are thinking primarily about endofunctors?  In that case every  
object and morphism in site lives in the same category, so it is  
natural to think that the natural transformations do also.  However, I  
don't think this is correct.  I think it is better to think of  
functors as occurring as bridges _between_ categories and natural  
transformations as existing _between_ functors.  More than just a  
collection of morphisms, a natural transformation actually associates  
objects and morphisms in the source category with morphisms and  
diagrams respectively in the target category.  Or, if you prefer the  
collection of morphisms in the target category is 'indexed' by the  
objects in the source category in such a way that morphisms between  
the indexing objects set up a natural relationship between the  
morphisms they index - that natural relationship is given by a  
commutative diagram.

> I hope these questions make sense. I really appreciate anyone who  
> takes to time to read this!
>
> Matt
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners



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

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


End of Beginners Digest, Vol 24, Issue 37
*****************************************

Reply via email to