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: small expression evaluator (Petr Novotnik)
2. Re: Recursion in monad (Adrian May)
3. Does haskell have to have values? (Mike Meyer)
4. Re: How to structure your Haskell installation? (frode k)
5. cabal dependencies question (Rob Nikander)
6. Re: cabal dependencies question (Daniel Fischer)
7. Re: Does haskell have to have values? (Patrick Lynch)
----------------------------------------------------------------------
Message: 1
Date: Wed, 23 Mar 2011 13:55:22 +0100
From: Petr Novotnik <[email protected]>
Subject: Re: [Haskell-beginners] small expression evaluator
To: Henk-Jan van Tuyl <[email protected]>
Cc: Haskell Beginners List <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-15; format=flowed
Hello Henk-Jan,
many thanks for your answer. Yes, I could do what you propose. But I
still wonder if it is possible or not to the "lifting" as I mentioned
earlier.
Again thanks for answering,
pete.
On 03/22/2011 01:43 PM, Henk-Jan van Tuyl wrote:
> On Tue, 22 Mar 2011 10:14:57 +0100, Henk-Jan van Tuyl
> <[email protected]> wrote:
>
>> On Tue, 22 Mar 2011 08:56:45 +0100, Petr Novotnik
>> <[email protected]> wrote:
>>
>>> data Person = Person {
>>> personName :: String
>>> , personAge :: Int
>>> }
>>> deriving (Show)
>>>
>>> exampleExpr :: Bool
>>> exampleExpr = (VConst 99) .==. (VFunc personAge) $ Person "pete" 99
>>>
>>>
>>> I was wondering, whether it'd be possible to enable defining
>>> expression without the Value data constructors, i.e.
>>>
>>>
>>> 99 .==. personAge $ Person "pete" 99
>>
>> You can write:
>> 99 == personAge (Person "pete" 99)
>>
>
> Or you could write:
> c .==. f = \x -> c == f x
>
> test = 99 .==. personAge $ Person "pete" 99
>
> The .==. operator is not symmetrical in this case, of course
>
> Regards,
> Henk-Jan van Tuyl
>
>
------------------------------
Message: 2
Date: Wed, 23 Mar 2011 23:46:31 +0800
From: Adrian May <[email protected]>
Subject: Re: [Haskell-beginners] Recursion in monad
To: Chadda? Fouch? <[email protected]>
Cc: [email protected]
Message-ID:
<[email protected]>
Content-Type: text/plain; charset="utf-8"
Hi Jedi (why not?)
Thanks for the tips...
> say i = putStrLn $ show i
>
> This already exist and is called "print" (though its type is more
> general than your signature).
>
>
So it is.
> > walk i = randomRIO (0,1) >>= \r -> return (i+r*2-1)
>
> The >>= ... return is pretty ugly, it would rather be written as :
>
> > walk i = fmap (\r -> i + r * 2 - 1) $ randomRIO (0,1)
>
>
Well, for the time being I like to see exactly what's happening with the
monads. That's why I don't use do. There'll come a day when I already know
and I'll bear it in mind for then.
> > rep n i w s
>
> Passing say and walk as parameter seems a bit overkill, I seriously
> doubt that you'll ever need this exact structure again, and even then
> passing a single action should be enough :
>
> > rep n act i
> > | n <= 0 = return ()
> > | otherwise = act i >>= \x -> rep (n-1) act x
>
>
But what do I pass for act? walk.say? say>>walk?
> rep may also be written with standard monad operations :
> > rep n act i = foldM (\x _ -> act x) i $ replicate (n-1) ()
>
>
Cunning. But it seems a bit round-the-houses to me. I mean, there's no
fundamental reason for that list of nothings; it's just plugging a hole in
haskell. My counter looks naive but at least it's to the point. I guess it's
a matter of taste.
> Lastly it may be that the structure of the program itself,
> particularly the use of randomRIO is suboptimal and a bit ugly, for a
> throwaway program I would probably just use randomRs :
>
> > main = do
> > g <- newStdGen
> > mapM_ print . tail . scanl (\i r -> i+r*2-1) 50 . take 10 $ randomRs
> (0,1) g
>
>
Are there some extra dots in there?
Actually, I can't let the number of random numbers control the number of
iterations because my algorithm asks for random numbers when it feels like
it. You can't predict how many unless you can predict the random numbers. My
main loop is like this:
step (w,i,o) = env o >>= \i' ->
think w i' >>= \o' ->
learn w i i' o o' >>= \w' ->
return (w', i', o')
I tried to tidy that up by factoring out that "remember the last iteration"
business. (It's a Hebbian learning rule.) I figured I could use a comonad
containing the current and previous values of i and o, a function that takes
both and returns the new value, and let cobind shuffle them along. It didn't
work though because I wasn't allowed to say:
instance Comonad (a,a) where ...
Apparently
instance Comonad ((,) a) where ...
is legal, but I really want to say that both elements of the tuple are the
same, otherwise everything else barfs. Is there some workaround for that?
The compiler seemed to imply that you can only ever have one parameter to a
type in an instance declaration, but that would see rather limiting and
arbitrary. What's the deal here?
Adrian.
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20110323/d7c9ce65/attachment-0001.htm>
------------------------------
Message: 3
Date: Wed, 23 Mar 2011 16:17:57 -0400
From: Mike Meyer <[email protected]>
Subject: [Haskell-beginners] Does haskell have to have values?
To: Haskell Beginners List <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset=US-ASCII
I'm working my way through Real World haskell, and so far have found
the experience quite pleasant (though the harder exercises seem to
require things net yet covered).
Among the comments in the IO chapter was a discussion of whether or
not some monad was or was not a function, which got me thinking.
Values in haskell aren't evaluated until they're needed. They're
implemented as thunks, meaning they're roughly zeroadic functions that
will return the value when called.
The syntax of the language seems to make treating values as zeroadic
functions that return the value in question a reasonable
interpretation as a degenerate case:
(+) accepts two arguments and returns their sum.
(+ 5) accepts one argument and returns that plus 5.
(3 + 5) accepts zero arguments and returns 8.
or (more pedantically):
(+) accepts one argument and returns a function that accepts one
argument and returns a zeroadic function that returns the
value of the sum of the two arguments.
(+ 5) accepts one argument and returns a zeroadic function that ...
(3 + 5) a zeroadic function that returns 8
So the question is - is there any advantage or harm in this way of
looking at values?
Thanks,
<mike
--
Mike Meyer <[email protected]> http://www.mired.org/consulting.html
Independent Software developer/SCM consultant, email for more information.
O< ascii ribbon campaign - stop html mail - www.asciiribbon.org
------------------------------
Message: 4
Date: Wed, 23 Mar 2011 21:56:06 +0100
From: frode k <[email protected]>
Subject: Re: [Haskell-beginners] How to structure your Haskell
installation?
To: beginners <[email protected]>
Message-ID:
<[email protected]>
Content-Type: text/plain; charset="iso-8859-1"
Thanks for your feedback, it helped me setting up both GHC 7.0.2 and 6.12.3
in parallel, and Cabal-install with the edited configuration file made it
all much easier. I only needed GHC 6.12.3 for building 7.0.2, hence I did
not bother installing / building Cabal-install for 6.12.3.
I did document the entire process here:
http://klevstul.posterous.com/haskell-ghc-702-on-centos-55
[k]
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20110323/466c955e/attachment-0001.htm>
------------------------------
Message: 5
Date: Wed, 23 Mar 2011 17:08:25 -0400
From: Rob Nikander <[email protected]>
Subject: [Haskell-beginners] cabal dependencies question
To: beginners <[email protected]>
Message-ID:
<[email protected]>
Content-Type: text/plain; charset=ISO-8859-1
Hi,
I was unable to normally install the "mime" package -- I got an error
that it needed "base <= 4". I have 4.3.1.0. So I ran `cabal unpack
mime`, edited mime.cabal to say "base <= 4.3.1.0" and from that file's
directory ran `cabal install'. It appeared to install it okay. But
when I try to install another package that needs mime, I get the same
kind of error:
> cabal install http-server
Resolving dependencies...
cabal: cannot configure mime-0.3.2. It requires base >=3 && <=4
For the dependency on base >=3 && <=4 there are these packages: base-3.0.3.1
and base-3.0.3.2. However none of them are available.
base-3.0.3.1 was excluded because base-4.3.1.0 was selected instead
I'm wondering why it thinks the mime package wants base <= 4 when I
just installed with a .cabal file that says base <= 4.3.1.0.
??
thanks,
Rob
------------------------------
Message: 6
Date: Wed, 23 Mar 2011 22:31:31 +0100
From: Daniel Fischer <[email protected]>
Subject: Re: [Haskell-beginners] cabal dependencies question
To: [email protected]
Message-ID: <[email protected]>
Content-Type: Text/Plain; charset="iso-8859-1"
On Wednesday 23 March 2011 22:08:25, Rob Nikander wrote:
> Hi,
>
> I was unable to normally install the "mime" package -- I got an error
> that it needed "base <= 4". I have 4.3.1.0. So I ran `cabal unpack
> mime`, edited mime.cabal to say "base <= 4.3.1.0" and from that file's
> directory ran `cabal install'. It appeared to install it okay. But
> when I try to install another package that needs mime, I get the same
>
> kind of error:
> > cabal install http-server
>
> Resolving dependencies...
> cabal: cannot configure mime-0.3.2. It requires base >=3 && <=4
> For the dependency on base >=3 && <=4 there are these packages:
> base-3.0.3.1 and base-3.0.3.2. However none of them are available.
> base-3.0.3.1 was excluded because base-4.3.1.0 was selected instead
>
> I'm wondering why it thinks the mime package wants base <= 4 when I
> just installed with a .cabal file that says base <= 4.3.1.0.
Because it tries to make a consistent install plan for the packages
incuding mime-0.3.2. For that it looks at the dependencies listed in the
package-index (because it knows where that is). That says mime-0.3.2 needs
base <= 4, so for a consistent install it would have to reinstall
mime-0.3.2, since a missing dependency indicates a broken package.
The solution (apart from prodding the maintainer to release a new version
compatible with base-4.3) is to bump the version of mime in your local
install, so
$ cd mime
-- edit mime.cabal to say the version is 0.3.2.1, save
$ cabal install
Now you have mime-0.3.2.1 installed and the package-index doesn't know
about that package, so cabal assumes that one is okay for further installs.
It won't work if the packages specify a dependency mime <= 0.3.2, in which
case you'd have to edit their .cabal files too (and don't forget to do a
minor-minor version bump for those).
Remember, everyone:
if you edit a .cabal file to repair the build-depends, bump the version or
cabal-install will think it's broken.
>
> ??
>
> thanks,
> Rob
HTH,
Daniel
------------------------------
Message: 7
Date: Wed, 23 Mar 2011 17:34:54 -0400
From: "Patrick Lynch" <[email protected]>
Subject: Re: [Haskell-beginners] Does haskell have to have values?
To: "Mike Meyer" <[email protected]>, "Haskell Beginners List"
<[email protected]>
Message-ID: <5D1F4F6A08E441D8A755D579557760C9@UserPC>
Content-Type: text/plain; format=flowed; charset=iso-8859-1;
reply-type=original
Hi,
I'm going thru RWH [Real World Haskell] too...
I'm finding it to be an excellent way to learn Haskell. I prefer it to the
Computer Scientist geared books that I'm also reading...
I also found "Learn You a Haskell for Great Good!" to be very worthwhile -
I've ordered a copy of it and it should be availble at the end of April, see
link:
http://book.realworldhaskell.org/read/code-case-study-parsing-a-binary-data-format.html
I found a link for RWH too - it is:
http://fldit-www.cs.uni-dortmund.de/~peter/RealWorldHaskell.pdf
BTW: I'm also an independent software consultant -- been doing it for 30+
years...
As for your question, I'm not, as yet, prepared to answer it...but it seems
to me that 'Sections' and 'Currying' are very important in the study of
Haskell...but I'm still in 'newbie' status...
I tried to install TK on my Windows Vista PC but was unable to do so...I
will try it again, using RWH - if you're heading there too, please let me
know - perhaps we can work this together...
I also took a look at Category Theory books but so far I'm stumped with it -
it's starting to make a bit of sense but I don't know if I'll be able to
link it to Haskell...
Good luck to both of us...
Pat
----- Original Message -----
From: "Mike Meyer" <[email protected]>
To: "Haskell Beginners List" <[email protected]>
Sent: Wednesday, March 23, 2011 4:17 PM
Subject: [Haskell-beginners] Does haskell have to have values?
> I'm working my way through Real World haskell, and so far have found
> the experience quite pleasant (though the harder exercises seem to
> require things net yet covered).
>
> Among the comments in the IO chapter was a discussion of whether or
> not some monad was or was not a function, which got me thinking.
>
> Values in haskell aren't evaluated until they're needed. They're
> implemented as thunks, meaning they're roughly zeroadic functions that
> will return the value when called.
>
> The syntax of the language seems to make treating values as zeroadic
> functions that return the value in question a reasonable
> interpretation as a degenerate case:
>
> (+) accepts two arguments and returns their sum.
> (+ 5) accepts one argument and returns that plus 5.
> (3 + 5) accepts zero arguments and returns 8.
>
> or (more pedantically):
>
> (+) accepts one argument and returns a function that accepts one
> argument and returns a zeroadic function that returns the
> value of the sum of the two arguments.
> (+ 5) accepts one argument and returns a zeroadic function that ...
> (3 + 5) a zeroadic function that returns 8
>
> So the question is - is there any advantage or harm in this way of
> looking at values?
>
> Thanks,
> <mike
> --
> Mike Meyer <[email protected]> http://www.mired.org/consulting.html
> Independent Software developer/SCM consultant, email for more information.
>
> O< ascii ribbon campaign - stop html mail - www.asciiribbon.org
>
> _______________________________________________
> 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 33, Issue 32
*****************************************