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: Pattern matching over functions (Daniel Fischer) 2. Matrix / Matrix Addition (Paul Monday) 3. Re: Matrix / Matrix Addition (Daniel Fischer) 4. Re: Matrix / Matrix Addition (Felipe Almeida Lessa) 5. Re: Matrix / Matrix Addition (Paul Monday) 6. Installing regex-pcre (MJ Williams) 7. Re: Installing regex-pcre (David McBride) 8. Re: Pattern matching over functions (Giacomo Tesio) ---------------------------------------------------------------------- Message: 1 Date: Thu, 8 Dec 2011 13:53:19 +0100 From: Daniel Fischer <daniel.is.fisc...@googlemail.com> Subject: Re: [Haskell-beginners] Pattern matching over functions To: beginners@haskell.org Message-ID: <201112081353.19444.daniel.is.fisc...@googlemail.com> Content-Type: Text/Plain; charset="iso-8859-1" On Thursday 08 December 2011, 07:14:39, Brent Yorgey wrote: > I, for one, am not > willing to give up these beautiful and powerful reasoning tools just > for a little gain in expressivity. > > -Brent Seconded, Daniel ------------------------------ Message: 2 Date: Thu, 8 Dec 2011 13:55:46 -0700 From: Paul Monday <paul.mon...@parsci.com> Subject: [Haskell-beginners] Matrix / Matrix Addition To: beginners@haskell.org Message-ID: <0983f510-9daa-46e5-8889-0019dc743...@parsci.com> Content-Type: text/plain; charset=windows-1252 I'm working on simple matrix / matrix addition for a short project. Doing this with lists (not worrying about matrix sizes and such) is relatively easy and makes quite a bit of sense to me: basically: madd :: Num a => [[a]] -> [[a]] -> [[a]] I could read this as: - with a as a Numeric type, take two lists of lists of Numerics and return a list of lists of Numerics And then to do the job simple madd m n = zipWith (zipWith (+)) m n And I can read that easily enough: -- madd has two inputs, m and n and it will do the function "zipWith (+)" across its inputs of the inner lists from m and n (the rows, basically) Ok, so madd [[1,2,3], [4,5,6], [7,8,9]] [[10,11,12], [13,14,5], [16,17,18]] yields [[11,13,15],[17,19,11],[23,25,27]] Cool I can get a little nicer (possibly) if I use a Matrix type: data Matrix a = Matrix [[a]] deriving (Show, Eq) madd :: Num a => [[a]] -> [[a]] -> [[a]] madd m n = zipWith (zipWith (+)) m n madd2 :: (Num a) => Matrix a -> Matrix a -> Matrix a madd2 (Matrix m) (Matrix n) = Matrix $ zipWith (zipWith (+)) m n The only real change in terms of the code is in the madd2 definition where I have to construct a Matrix to return from the results of the zipWiths ? and some better type safety of course. *Main> madd2 (Matrix [[1,2,3], [4,5,6], [7,8,9]]) (Matrix [[10,11,12], [13,14,5], [16,17,18]]) Matrix [[11,13,15],[17,19,11],[23,25,27]] Cool' Now, I really want to use Unboxed Vectors. As I look around the web and poke around through various resources, I believe that I need the rows to be unboxed but the columns can be boxed ? the actual operations on the rows will give me the speed up I desire. So, here it is: import qualified Data.Vector as V import qualified Data.Vector.Unboxed as U data UMatrix a = UMatrix (V.Vector (U.Vector a)) deriving (Show, Eq) madd3 :: (U.Unbox a, Num a) => UMatrix a -> UMatrix a -> UMatrix a madd3 (UMatrix m) (UMatrix n) = UMatrix $ V.zipWith (U.zipWith (+)) m n And it works ? (really, when I started writing this note, I was completely lost ? welcome to the power of sitting and walking through Haskell) madd3 (UMatrix (Data.Vector.fromList [Data.Vector.Unboxed.fromList [1,2,3], Data.Vector.Unboxed.fromList [4,5,6], Data.Vector.Unboxed.fromList [7,8,9]])) (UMatrix (Data.Vector.fromList [Data.Vector.Unboxed.fromList [10,11,12], Data.Vector.Unboxed.fromList [13,14,5], Data.Vector.Unboxed.fromList [16,17,18]])) I have ONE thing that I can't really explain ? Why does the declaration of madd3 REQUIRE the use of U.Unbox a as a data type? madd3 :: (U.Unbox a, Num a) => UMatrix a -> UMatrix a -> UMatrix a I would have thought that my declaration of UMatrix would have done this? Cheers. Paul Monday Parallel Scientific, LLC. paul.mon...@parsci.com ------------------------------ Message: 3 Date: Thu, 8 Dec 2011 22:13:20 +0100 From: Daniel Fischer <daniel.is.fisc...@googlemail.com> Subject: Re: [Haskell-beginners] Matrix / Matrix Addition To: beginners@haskell.org Message-ID: <201112082213.20678.daniel.is.fisc...@googlemail.com> Content-Type: Text/Plain; charset="windows-1252" On Thursday 08 December 2011, 21:55:46, Paul Monday wrote: > data UMatrix a = UMatrix (V.Vector (U.Vector a)) > deriving (Show, Eq) > > madd3 :: (U.Unbox a, Num a) => UMatrix a -> UMatrix a -> UMatrix a > madd3 (UMatrix m) (UMatrix n) = UMatrix $ V.zipWith (U.zipWith (+)) m n > > And it works ? (really, when I started writing this note, I was > completely lost ? welcome to the power of sitting and walking through > Haskell) > > madd3 (UMatrix (Data.Vector.fromList [Data.Vector.Unboxed.fromList > [1,2,3], Data.Vector.Unboxed.fromList [4,5,6], > Data.Vector.Unboxed.fromList [7,8,9]])) (UMatrix (Data.Vector.fromList > [Data.Vector.Unboxed.fromList [10,11,12], Data.Vector.Unboxed.fromList > [13,14,5], Data.Vector.Unboxed.fromList [16,17,18]])) > > I have ONE thing that I can't really explain ? > > Why does the declaration of madd3 REQUIRE the use of U.Unbox a as a data > type? madd3 :: (U.Unbox a, Num a) => UMatrix a -> UMatrix a -> UMatrix > a > > I would have thought that my declaration of UMatrix would have done > this? No, the data declaration doesn't provide any such context, hence you have to specify it at the use site (I don't think for types which aren't instances of Unbox there are any values other than _|_, though). You can make the Unbox constraint available from the data declaration if you use GADTs, {-# LANGUAGE GADTs #-} data UMatrix e where UMatrix :: U.Unbox a => V.Vector (U.Vector a) -> UMatrix a Then pattern-matching on a UMatrix makes the Unbox dictionary of a available. ------------------------------ Message: 4 Date: Thu, 8 Dec 2011 19:24:13 -0200 From: Felipe Almeida Lessa <felipe.le...@gmail.com> Subject: Re: [Haskell-beginners] Matrix / Matrix Addition To: Paul Monday <paul.mon...@parsci.com> Cc: beginners@haskell.org Message-ID: <CANd=OGHizA=dye2g_tdd-2kk0df9hteo+bffd_nz659m4m+...@mail.gmail.com> Content-Type: text/plain; charset=UTF-8 On Thu, Dec 8, 2011 at 6:55 PM, Paul Monday <paul.mon...@parsci.com> wrote: > data UMatrix a = UMatrix (V.Vector (U.Vector a)) > ? ?deriving (Show, Eq) Note that you may also use something like data UMatrix a = UMatrix !Int !(U.Vector a) where the Int is the number of columns. Cheers, -- Felipe. ------------------------------ Message: 5 Date: Thu, 8 Dec 2011 15:04:43 -0700 From: Paul Monday <paul.mon...@parsci.com> Subject: Re: [Haskell-beginners] Matrix / Matrix Addition To: Daniel Fischer <daniel.is.fisc...@googlemail.com> Cc: beginners@haskell.org Message-ID: <a3b0a960-3379-44b1-83ea-23b65e6a0...@parsci.com> Content-Type: text/plain; charset="windows-1252" Perfect ? Thanks Daniel! Paul Monday Parallel Scientific, LLC. paul.mon...@parsci.com On Dec 8, 2011, at 2:13 PM, Daniel Fischer wrote: > On Thursday 08 December 2011, 21:55:46, Paul Monday wrote: >> data UMatrix a = UMatrix (V.Vector (U.Vector a)) >> deriving (Show, Eq) >> >> madd3 :: (U.Unbox a, Num a) => UMatrix a -> UMatrix a -> UMatrix a >> madd3 (UMatrix m) (UMatrix n) = UMatrix $ V.zipWith (U.zipWith (+)) m n >> >> And it works ? (really, when I started writing this note, I was >> completely lost ? welcome to the power of sitting and walking through >> Haskell) >> >> madd3 (UMatrix (Data.Vector.fromList [Data.Vector.Unboxed.fromList >> [1,2,3], Data.Vector.Unboxed.fromList [4,5,6], >> Data.Vector.Unboxed.fromList [7,8,9]])) (UMatrix (Data.Vector.fromList >> [Data.Vector.Unboxed.fromList [10,11,12], Data.Vector.Unboxed.fromList >> [13,14,5], Data.Vector.Unboxed.fromList [16,17,18]])) >> >> I have ONE thing that I can't really explain ? >> >> Why does the declaration of madd3 REQUIRE the use of U.Unbox a as a data >> type? madd3 :: (U.Unbox a, Num a) => UMatrix a -> UMatrix a -> UMatrix >> a >> >> I would have thought that my declaration of UMatrix would have done >> this? > > No, the data declaration doesn't provide any such context, hence you have > to specify it at the use site (I don't think for types which aren't > instances of Unbox there are any values other than _|_, though). > > You can make the Unbox constraint available from the data declaration if > you use GADTs, > > {-# LANGUAGE GADTs #-} > > data UMatrix e where > UMatrix :: U.Unbox a => V.Vector (U.Vector a) -> UMatrix a > > Then pattern-matching on a UMatrix makes the Unbox dictionary of a > available. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://www.haskell.org/pipermail/beginners/attachments/20111208/0d7550ff/attachment-0001.htm> ------------------------------ Message: 6 Date: Thu, 08 Dec 2011 23:09:15 +0000 From: MJ Williams <matthewjwilliams...@gmail.com> Subject: [Haskell-beginners] Installing regex-pcre To: beginners@haskell.org Message-ID: <4ee14396.04c6e30a.1281.1...@mx.google.com> Content-Type: text/plain; charset="us-ascii"; format=flowed Dear all, I'm trying to install regex-pcre on my XP Pro machine. I have the latest version of GHC. Do any of you recognise and understand the following error message? install regex-pcre Resolving dependencies... Configuring regex-pcre-0.94.2... cabal: Missing dependency on a foreign library: * Missing C library: pcre This problem can usually be solved by installing the system package that provides this library (you may need the "-dev" version). If the library is already installed but in a non-standard location then you can use the flags --extra-include-dirs= and --extra-lib-dirs= to specify where it is. cabal: Error: some packages failed to install: regex-pcre-0.94.2 failed during the configure step. The exception was: ExitFailure 1 Apologies if the query is a little offtopic. Regards Matthew ------------------------------ Message: 7 Date: Thu, 8 Dec 2011 18:25:58 -0500 From: David McBride <toa...@gmail.com> Subject: Re: [Haskell-beginners] Installing regex-pcre To: MJ Williams <matthewjwilliams...@gmail.com> Cc: beginners@haskell.org Message-ID: <can+tr43fqyma92osxrf0rgznueqsws5mavtijf+p190g7o2...@mail.gmail.com> Content-Type: text/plain; charset=ISO-8859-1 That package requires the C library 'libpcre'. It is extremely common on unix systems, but I don't know if it exists in windows. You'll have to do some research on that. On Thu, Dec 8, 2011 at 6:09 PM, MJ Williams <matthewjwilliams...@gmail.com> wrote: > Dear all, > I'm trying to install regex-pcre on my XP Pro machine. ?I have the latest > version of GHC. ?Do any of you recognise and understand the following error > message? > > install regex-pcre > Resolving dependencies... > Configuring regex-pcre-0.94.2... > cabal: Missing dependency on a foreign library: > * Missing C library: pcre > This problem can usually be solved by installing the system package that > provides this library (you may need the "-dev" version). If the library is > already installed but in a non-standard location then you can use the flags > --extra-include-dirs= and --extra-lib-dirs= to specify where it is. > cabal: Error: some packages failed to install: > regex-pcre-0.94.2 failed during the configure step. The exception was: > ExitFailure 1 > > > Apologies if the query is a little offtopic. > Regards > Matthew > > > _______________________________________________ > Beginners mailing list > Beginners@haskell.org > http://www.haskell.org/mailman/listinfo/beginners ------------------------------ Message: 8 Date: Fri, 9 Dec 2011 07:42:04 +0100 From: Giacomo Tesio <giac...@tesio.it> Subject: Re: [Haskell-beginners] Pattern matching over functions To: Daniel Fischer <daniel.is.fisc...@googlemail.com> Cc: beginners@haskell.org Message-ID: <cahl7pseogp68racfxkk6-_pbm1-s7+9xfcv8j_drddkhktd...@mail.gmail.com> Content-Type: text/plain; charset="utf-8" I agree. I think I got it, without the ability to correctly match equivalent morphisms, morphisms can't be treated as objects. Probably such ability would require a very powerful runtime, but I don't think that it would be just matter of expressivity (and you would not loose referential transparency as (+3) would be matched with (\x -> 5 + x - 2). Giacomo On Thu, Dec 8, 2011 at 1:53 PM, Daniel Fischer < daniel.is.fisc...@googlemail.com> wrote: > On Thursday 08 December 2011, 07:14:39, Brent Yorgey wrote: > > I, for one, am not > > willing to give up these beautiful and powerful reasoning tools just > > for a little gain in expressivity. > > > > -Brent > > Seconded, > > Daniel > > _______________________________________________ > Beginners mailing list > Beginners@haskell.org > http://www.haskell.org/mailman/listinfo/beginners > -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://www.haskell.org/pipermail/beginners/attachments/20111209/bb84de56/attachment.htm> ------------------------------ _______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners End of Beginners Digest, Vol 42, Issue 10 *****************************************