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:  Monads (Patrick Lynch)
   2. Re:  Nested data types and bisimilarity (Brent Yorgey)
   3.  HDBC - outside a transaction (Petr Novotnik)
   4. Re:  Nested data types and bisimilarity (Berlin Brown)


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

Message: 1
Date: Mon, 07 Mar 2011 08:53:25 -0500
From: "Patrick Lynch" <kmandpjly...@verizon.net>
Subject: Re: [Haskell-beginners] Monads
To: "Brent Yorgey" <byor...@seas.upenn.edu>
Cc: beginners@haskell.org
Message-ID: <58B76258AE784A2E9FBDEB6A1EA19B52@UserPC>
Content-Type: text/plain; format=flowed; charset=iso-8859-1;
        reply-type=original

...i'm about half way thru "Real World Haskell" - I'm about to start its 
section on Monads...I'll let you know...
Thanks for your good advice...
Ciao

----- Original Message ----- 
From: "Brent Yorgey" <byor...@seas.upenn.edu>
To: "Patrick Lynch" <kmandpjly...@verizon.net>
Cc: <beginners@haskell.org>
Sent: Saturday, March 05, 2011 10:11 AM
Subject: Re: [Haskell-beginners] Monads


> On Sat, Mar 05, 2011 at 09:25:21AM -0500, Patrick Lynch wrote:
>> Brent,
>>
>> Eureeka! I'll be damned - I can create my own class...(I had a 'typo'
>> in my class MyCalculator class code -- that is, myadd::...should be
>> myAdd::...) it works just fine...thank you. You should of bet me...
>> I've purchased Awodey's book: "Category Theory"...thanks again...
>>
>> I've got the following books on my reading list:
>>    "Programming in Haskell" by Graham Hutton
>>    "Learn You a Haskell for Great Good!" by Miran Lipovaca
>>    "Real World Haskell" by Bryan O'Sullivan, etal
>>    "The Haskell Road to Logic, Maths and Programming" by Kees Doets, etal
>>    "An Introduction to Functioanl Programming Systems Using Haskell"
>> by A.J.T Davie
>>    "Introduction to Functional Programming using Haskell" by Richard Bird
>>    "The Craft of Functional Programming" by Simon Thompson
>> I've been working with Simon Thompson, so I'll start working his book
>> next...
>>
>> If you can recommend a book that covers Monads [for a mere practicing
>> software consultant], I'd welcome it...
>
> Real World Haskell is such a book -- I haven't read the part about
> monads but I've heard good things about it, that it introduces them in
> a quite practical, example-driven, no-nonsense way.
>
> -Brent
>
>>
>> Good weekend,
>> Pat
>>
>> ----- Original Message ----- From: "Brent Yorgey"
>> <byor...@seas.upenn.edu>
>> To: "Patrick Lynch" <kmandpjly...@verizon.net>
>> Cc: <beginners@haskell.org>
>> Sent: Friday, March 04, 2011 11:33 PM
>> Subject: Re: [Haskell-beginners] Monads
>>
>>
>> >On Fri, Mar 04, 2011 at 05:20:27PM -0500, Patrick Lynch wrote:
>> >>
>> >>I'd love to take a crack at Category Theory [my mathematics is good]
>> >>but this looks like a formidable task...
>> >
>> >It is not that formidable just to get started.  But it is so abstract
>> >that it can be difficult to gain intuition for.  If you want to learn
>> >some category theory I recommend Awodey's book.
>> >
>> >>I'll proceed using the Monad classes and instances as is - and hope
>> >>that at some point I'll be able to create my own Monads...
>> >
>> >Creating one's own monads is overrated.  I almost never do it.
>> >Usually I can just put something together using monad transformers
>> >that fits my needs.
>> >
>> >>
>> >>btw: can you create a class in Haskell -[I'm guessing the answer to
>> >>this is no -- see below, it doesn't work]?
>> >>
>> >>    class MyCalculator a where
>> >>    myadd::( Num a) => a -> a -> a
>> >>    myAdd x y = x + y
>> >
>> >Sure, you can do that.  What do you mean when you say that it doesn't
>> >work?
>> >
>> >-Brent
>> >
>> >>
>> >>----- Original Message ----- From: "Brent Yorgey"
>> >><byor...@seas.upenn.edu>
>> >>To: <beginners@haskell.org>
>> >>Cc: "Patrick Lynch" <kmandpjly...@verizon.net>
>> >>Sent: Friday, March 04, 2011 3:07 PM
>> >>Subject: Re: [Haskell-beginners] Monads
>> >>
>> >>
>> >>>On Wed, Mar 02, 2011 at 04:38:07PM -0500, Patrick Lynch wrote:
>> >>>>
>> >>>>----- Original Message ----- From: "Brent Yorgey"
>> >>>><byor...@seas.upenn.edu>
>> >>>>To: <beginners@haskell.org>
>> >>>>Sent: Wednesday, March 02, 2011 10:37 AM
>> >>>>Subject: Re: [Haskell-beginners] Monads
>> >>>>
>> >>>>
>> >>>>>On Wed, Mar 02, 2011 at 10:04:38AM -0500, Patrick Lynch wrote:
>> >>>>>>Daniel,
>> >>>>>>Thank you...I understand now...
>> >>>>>>Good day
>> >>>>>>
>> >>>>>>    instance Functor Maybe where
>> >>>>>>      fmap f (Just x) = Just (f x)
>> >>>>>>      fmap f Nothing = Nothing
>> >>>>>
>> >>>>>So you are confused about this code?  Can you be more specific what
>> >>>>>you are confused about?  Try thinking carefully about all the types
>> >>>>>involved.  What is the type of f? (You already answered this: a -> 
>> >>>>>b.)
>> >>>>>What is the type of (Just x)? The type of x?  What type is required 
>> >>>>>on
>> >>>>>the right hand side of the = ?  And so on.
>> >>>>
>> >>>>
>> >>>>-Hi Brent
>> >>>>I know that Maybe type is: data Maybe a = Nothing | Just a
>> >>>>...so, I assume that the type to the right of the '=' should be
>> >>>>Maybe a..
>> >>>
>> >>>Not quite.  Let's look again at the type of fmap here:
>> >>>
>> >>> fmap :: (a -> b) -> Maybe a -> Maybe b
>> >>>
>> >>>So fmap will be taking *two* parameters, the first of type (a -> b),
>> >>>the second of type Maybe a.  Then it needs to return something of type
>> >>>Maybe b (so this is what will be on the right hand side of the =).
>> >>>
>> >>>>    instance Functor Maybe where
>> >>>>      fmap Nothing = Nothing
>> >>>>      fmap Just x = Just x
>> >>>
>> >>>You're missing the first argument to fmap (the one of type a -> b).
>> >>>Let's call it f.  Since the second argument is of type (Maybe a)
>> >>>you're right that we should handle all cases (Nothing and Just).
>> >>>
>> >>> fmap f Nothing = Nothing
>> >>>
>> >>>so here we need to return something of type 'Maybe b'.  Well, we don't
>> >>>have any values of type b, so the only thing we can do is return
>> >>>Nothing.
>> >>>
>> >>> fmap f (Just x) = ?
>> >>>
>> >>>The reason we need the parentheses around (Just x) is simply that
>> >>>otherwise the compiler thinks we are writing a definition of fmap that
>> >>>takes three arguments: f, Just, and x, but that doesn't make sense.
>> >>>
>> >>>Now, here f has type (a -> b), and (Just x) has type (Maybe a), hence
>> >>>x has type a.  If we apply f to x we get something of type b, so we
>> >>>can define
>> >>>
>> >>> fmap f (Just x) = Just (f x)
>> >>>
>> >>>Does that make sense?
>> >>>
>> >>>-Brent
>> >>
>> 




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

Message: 2
Date: Mon, 7 Mar 2011 16:30:44 -0500
From: Brent Yorgey <byor...@seas.upenn.edu>
Subject: Re: [Haskell-beginners] Nested data types and bisimilarity
To: dan portin <danpor...@gmail.com>
Cc: beginners@haskell.org
Message-ID: <20110307213044.ga9...@seas.upenn.edu>
Content-Type: text/plain; charset=us-ascii

On Sat, Mar 05, 2011 at 03:17:57AM -0800, dan portin wrote:
> > Actually, you are missing the point. ;)  The point of bisimulations is
> > that they are defined *coinductively*, so they let you work with
> > potentially infinite data structures.  In your example, proving that
> > xs and ys are in the relation R really is that simple -- 1 = 1, and
> > then to complete the proof we are allowed to use the coinduction
> > hypothesis that xs and ys are in the relation R, since they are
> > guarded by a constructor (:).
> >
> > Dan, does this help answer your original question?  If not I can try
> > to give a more detailed answer in the morning.
> >
> 
> I understand the coinduction principle for data structures like streams
> (e.g., Felipe's example) and finitely branching trees (from papers like "A
> calculus of binary trees"). In general, for lists and types constructed from
> arrow, product, and so on, it's easy to define conditions for a relation to
> be a bisimulation. For instance, I know that a relation *R* is a
> bisimulation over *n*-branching trees *t1 *and *t2* (for some *n*) if their
> roots are equal and each of their subtrees are in *R*. My problem is,
> specifically, with the case of infinitely branching trees. In Haskell, these
> are modeled by the data type
> 
> T a = T a [T a]
> 
> and the possibility arises, of course, that the list [T a] is a stream.
> Clearly, we can't just say that a relation *R* is a bisimulation on trees *
> t1* and *t2* of type T a if their root values are equal and their *lists* of
> subtrees are equal. Because if the lists are infinite, we have to prove that
> they are bisimilar. And the coinduction principle for lists requires us to
> have established that the head of each list is equal. But this is what we're
> trying to prove!

I don't actually see a problem here, as long as we generalize the
notion of "equality" to "bisimilarity" (which is of course the point
of bisimilarity).  We say that two trees are bisimilar if there is a
relation R, for which

   * if the roots of the two trees are equal
   * and their forest-streams are bisimilar

then the trees are in relation R.

It's perfectly fine that the notion of bisimilarity for the
forest-streams is defined in terms of bisimilarity of trees.  Perhaps
to be completely rigorous we should say that we define the notions of
bisimilarity for trees and for streams of trees by simultaneous
coinduction.

-Brent



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

Message: 3
Date: Tue, 08 Mar 2011 08:54:44 +0100
From: Petr Novotnik <pnovot...@googlemail.com>
Subject: [Haskell-beginners] HDBC - outside a transaction
To: Haskell Beginners List <beginners@haskell.org>
Message-ID: <4d75e0c4.4040...@googlemail.com>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed

Hello all,

while working through `Real World Haskell' Chapter 21 I hit the 
following problem:

Using sqlite3, enabling foreign keys with "PRAGMA foreign_keys = ON;" 
must be done outside a transaction. However, HDBC doesn't seem to 
provide a possibility to submit such a statement to the database outside 
of a transaction.

The only workaround I've found looks like this:

> openDatabase :: String -> IO Connection
> openDatabase name = do
>   conn <- connectSqlite3 name
>   run conn "COMMIT;" [] -- manually close HDBC's underlyingTX
>   run conn "PRAGMA foreign_keys = ON;" [] -- execute outside of TX
>   run conn "BEGIN;" [] -- open a new TX for HDBC again
>   prepareDatabase conn
>   return conn

Am I missing something in HDBC's API or is this the only way to do it?

Many thanks in advance,
Pete.



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

Message: 4
Date: Tue, 8 Mar 2011 03:11:36 -0500
From: Berlin Brown <berlin.br...@gmail.com>
Subject: Re: [Haskell-beginners] Nested data types and bisimilarity
To: Brent Yorgey <byor...@seas.upenn.edu>
Cc: beginners@haskell.org
Message-ID:
        <AANLkTi=ZK9iD=9v_byxapuvfktn-uiesx0dnuuwe2...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"

On Mon, Mar 7, 2011 at 4:30 PM, Brent Yorgey <byor...@seas.upenn.edu> wrote:

> On Sat, Mar 05, 2011 at 03:17:57AM -0800, dan portin wrote:
> > > Actually, you are missing the point. ;)  The point of bisimulations is
> > > that they are defined *coinductively*, so they let you work with
> > > potentially infinite data structures.  In your example, proving that
> > > xs and ys are in the relation R really is that simple -- 1 = 1, and
> > > then to complete the proof we are allowed to use the coinduction
> > > hypothesis that xs and ys are in the relation R, since they are
> > > guarded by a constructor (:).
> > >
> > > Dan, does this help answer your original question?  If not I can try
> > > to give a more detailed answer in the morning.
> > >
> >
> > I understand the coinduction principle for data structures like streams
> > (e.g., Felipe's example) and finitely branching trees (from papers like
> "A
> > calculus of binary trees"). In general, for lists and types constructed
> from
> > arrow, product, and so on, it's easy to define conditions for a relation
> to
> > be a bisimulation. For instance, I know that a relation *R* is a
> > bisimulation over *n*-branching trees *t1 *and *t2* (for some *n*) if
> their
> > roots are equal and each of their subtrees are in *R*. My problem is,
> > specifically, with the case of infinitely branching trees. In Haskell,
> these
> > are modeled by the data type
> >
> > T a = T a [T a]
> >
> > and the possibility arises, of course, that the list [T a] is a stream.
> > Clearly, we can't just say that a relation *R* is a bisimulation on trees
> *
> > t1* and *t2* of type T a if their root values are equal and their *lists*
> of
> > subtrees are equal. Because if the lists are infinite, we have to prove
> that
> > they are bisimilar. And the coinduction principle for lists requires us
> to
> > have established that the head of each list is equal. But this is what
> we're
> > trying to prove!
>
> I don't actually see a problem here, as long as we generalize the
> notion of "equality" to "bisimilarity" (which is of course the point
> of bisimilarity).  We say that two trees are bisimilar if there is a
> relation R, for which
>
>   * if the roots of the two trees are equal
>   * and their forest-streams are bisimilar
>
> then the trees are in relation R.
>
> It's perfectly fine that the notion of bisimilarity for the
> forest-streams is defined in terms of bisimilarity of trees.  Perhaps
> to be completely rigorous we should say that we define the notions of
> bisimilarity for trees and for streams of trees by simultaneous
> coinduction.
>
> -Brent
>
> _______________________________________________
> Beginners mailing list
> Beginners@haskell.org
> http://www.haskell.org/mailman/listinfo/beginners
>


I tried, nothing seems to work.  But, here is my configuration for the other
poor souls.

C:\Documents and Settings\Usr Berlin>echo %PATH%
C:\Program Files\Gtk+\bin;C:\Program Files\Haskell\bin;C:\Program
Files\Haskell
Platform\2010.2.0.0\lib\extralibs\bin;C:\Program Files\Haskell
Platform\2010.2.0
.0\bin; ... and other stuff

C:\Documents and Settings\Usr Berlin>echo %PKG_CONFIG_PATH%
C:\Program Files\Gtk+\lib\pkgconfig;C:\Program
Files\Gtk+\include\libglade-2.0;C
:\Program Files\libxml2\libxml2-dev_2.7.7-1_win32\lib\pkgconfig


C:\Documents and Settings\Usr Berlin>echo %INCLUDE%
C:\Program Files\Gtk+\include;C:\Program
Files\libxml2\libxml2-dev_2.7.7-1_win32
\include;C:\Program Files\Gtk+\include\libglade-2.0;C:\Program
Files\Gtk+\includ
e

C:\Documents and Settings\Usr Berlin>pkg-config.exe --modversion gtk+-2.0
2.16.2

C:\Documents and Settings\Usr Berlin>pkg-config --cflags gtk+-2.0
Files/Gtk+/include/gtk-2.0 -mms-bitfields Files/Gtk+/lib/gtk-2.0/include
Files/G
tk+/include/atk-1.0 Files/Gtk+/include/cairo Files/Gtk+/include/pango-1.0
Files/
Gtk+/include/glib-2.0 Files/Gtk+/lib/glib-2.0/include
Files/Gtk+/include/libpng1
2 -IC:/Program

C:\Documents and Settings\Usr Berlin>cabal update
Downloading the latest package list from hackage.haskell.org


C:\Documents and Settings\Usr Berlin>cabal install gtk
Resolving dependencies...
C:\DOCUME~1\UsrBER~1\LOCALS~1\Temp\cairo-0.12.043564\cairo-0.12.0\Gtk2HsSetup.h
:25: warning: #warning Setup.hs is guessing the version of Cabal. If
compilatio
 of Setup.hs fails use -DCABAL_VERSION_MINOR=x for Cabal version 1.x.0 when
bui
ding (prefixed by --ghc-option= when using the 'cabal' command)
[1 of 2] Compiling Gtk2HsSetup      (
C:\DOCUME~1\UsrBER~1\LOCALS~1\Temp\cairo-
.12.043564\cairo-0.12.0\Gtk2HsSetup.hs,
C:\DOCUME~1\UsrBER~1\LOCALS~1\Temp\cair
-0.12.043564\cairo-0.12.0\dist\setup\Gtk2HsSetup.o )
[2 of 2] Compiling Main             (
C:\DOCUME~1\UsrBER~1\LOCALS~1\Temp\cairo-
.12.043564\cairo-0.12.0\Setup.hs,
C:\DOCUME~1\UsrBER~1\LOCALS~1\Temp\cairo-0.12
043564\cairo-0.12.0\dist\setup\Main.o )
Linking
C:\DOCUME~1\UsrBER~1\LOCALS~1\Temp\cairo-0.12.043564\cairo-0.12.0\dist\
etup\setup.exe ...
Configuring cairo-0.12.0...
setup.exe: Missing dependencies on foreign libraries:
* Missing C libraries: z, cairo
This problem can usually be solved by installing the system packages that
provide these libraries (you may need the "-dev" versions). If the libraries
are already installed but in a non-standard location then you can use the
flags --extra-include-dirs= and --extra-lib-dirs= to specify where they are.
C:\DOCUME~1\UsrBER~1\LOCALS~1\Temp\glib-0.12.043564\glib-0.12.0\Gtk2HsSetup.hs:
5: warning: #warning Setup.hs is guessing the version of Cabal. If
compilation
f Setup.hs fails use -DCABAL_VERSION_MINOR=x for Cabal version 1.x.0 when
build
ng (prefixed by --ghc-option= when using the 'cabal' command)
[1 of 2] Compiling Gtk2HsSetup      (
C:\DOCUME~1\UsrBER~1\LOCALS~1\Temp\glib-0
12.043564\glib-0.12.0\Gtk2HsSetup.hs,
C:\DOCUME~1\UsrBER~1\LOCALS~1\Temp\glib-0
12.043564\glib-0.12.0\dist\setup\Gtk2HsSetup.o )
[2 of 2] Compiling Main             (
C:\DOCUME~1\UsrBER~1\LOCALS~1\Temp\glib-0
12.043564\glib-0.12.0\Setup.hs,
C:\DOCUME~1\UsrBER~1\LOCALS~1\Temp\glib-0.12.04
564\glib-0.12.0\dist\setup\Main.o )
Linking
C:\DOCUME~1\UsrBER~1\LOCALS~1\Temp\glib-0.12.043564\glib-0.12.0\dist\se
up\setup.exe ...
Configuring glib-0.12.0...
setup.exe: Missing dependencies on foreign libraries:
* Missing C libraries: gobject-2.0, glib-2.0, intl
This problem can usually be solved by installing the system packages that
provide these libraries (you may need the "-dev" versions). If the libraries
are already installed but in a non-standard location then you can use the
flags --extra-include-dirs= and --extra-lib-dirs= to specify where they are.
cabal: Error: some packages failed to install:
cairo-0.12.0 failed during the configure step. The exception was:
ExitFailure 1
gio-0.12.0 depends on glib-0.12.0 which failed to install.
glib-0.12.0 failed during the configure step. The exception was:
ExitFailure 1
gtk-0.12.0 depends on glib-0.12.0 which failed to install.
pango-0.12.0 depends on glib-0.12.0 which failed to install.




-- 
Berlin Brown (berlin dot brown at gmail.com)
http://botnode.com
http://berlinbrowndev.blogspot.com/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20110308/d823e8bf/attachment.htm>

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

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


End of Beginners Digest, Vol 33, Issue 9
****************************************

Reply via email to