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: Monadic composition without throwing genericity under
the bus? (Heinrich Apfelmus)
2. Re: Just clarifying the "pred" and "succ" functions in
Haskell (Felipe Lessa)
3. How to initialize a C struct with FFI (Marco De Oliveira)
4. Re: Installing hmatrix on OS X (Duncan Mortimer)
5. Re: Installing hmatrix on OS X (Duncan Mortimer)
6. Re: Typeclass problems (Patrick LeBoutillier)
7. Re: Re: Monadic composition without throwing genericity
under the bus? (Dave Bayer)
----------------------------------------------------------------------
Message: 1
Date: Sat, 06 Feb 2010 11:38:11 +0100
From: Heinrich Apfelmus <[email protected]>
Subject: [Haskell-beginners] Re: Monadic composition without throwing
genericity under the bus?
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=UTF-8
Stephen Tetley wrote:
> The parser has a type restricted return type - always a 'Hughes
> string' with efficient concatenation (ShowS :: String -> String)
> rather than some polymorphic answer (e.g a parse tree). For formatting
> it allows you to add text without consuming any:
>
> inserttext :: String -> Parser
> inserttext str = return (showString str)
>
> Or rewrite matched input:
>
> rewrite :: String -> String -> Parser
> rewrite inp out = string inp >> return (showString out)
>
> Or drop text, I presume this is what the place combinator does.
>
> Its a nice technique.
Ah, nice; thanks for the explanation!
Regards,
Heinrich Apfelmus
--
http://apfelmus.nfshost.com
------------------------------
Message: 2
Date: Sat, 6 Feb 2010 09:02:31 -0200
From: Felipe Lessa <[email protected]>
Subject: Re: [Haskell-beginners] Just clarifying the "pred" and "succ"
functions in Haskell
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii
On Sat, Feb 06, 2010 at 01:45:58AM -0500, Brandon S. Allbery KF8NH wrote:
> Andy Elvey wrote:
> >So, I may look at doing what I would call "lpred" and lsucc" - the
> >predecessor and successor of a list element. I'm somewhat
> >surprised that (from what I can tell) Haskell doesn't seem to have
> >those two functions for a list. I may be wrong....
>
> Again, lists don't work that way; a list in Haskell is a single
> immutable object, you can pull items from it using (!!), head, etc.,
> but you can't have a pointer into the "middle" of a list. You can
> have a sublist (for example, `tail ["foo", "bar", "baz"]' = `["bar",
> "baz"]') --- but you can't get from there to the "foo", as it isn't
> part of that new list. (This despite the fact that what `tail'
> gives you is going to be shared in actual storage with the original
> list. You don't have a backpointer into that original list to
> follow.)
Although we can't have a pointer to the middle of a list [a], we
can have another data struture that behaves sort of as if we had
that pointer: a zipper. For example,
http://hackage.haskell.org/packages/archive/ListZipper/1.1.1.0/doc/html/Data-List-Zipper.html
To understand a list zipper you could think of it as something like
struct zipper {
list left, right;
}
So we track our "position" by tracking what's on the left and
what's on the right. By using the API of the link above you
could have something similar to what you wanted:
lpred :: Zipper a -> a
lpred = focus . left
lsucc :: Zipper a -> a
lsucc = focus . right
--
Felipe.
------------------------------
Message: 3
Date: Sat, 6 Feb 2010 12:28:31 +0100
From: Marco De Oliveira <[email protected]>
Subject: [Haskell-beginners] How to initialize a C struct with FFI
To: [email protected]
Message-ID:
<[email protected]>
Content-Type: text/plain; charset="iso-8859-1"
Hi,
I try to initialize a C struct using the FFI API and ghc stays blocked when
I execute my code (and I got sometimes the error "out of memory").
I do not understand, I do not find any mistake in my code:
{-# OPTIONS -XTypeSynonymInstances #-}
import Foreign.C.Types
import Foreign.Marshal.Alloc
import Foreign.Ptr
import Foreign.Storable
type CStruct = (CULong, CULong)
instance Storable CStruct where
sizeOf _ = 2*sizeOf (undefined::CULong)
alignment _ = alignment (undefined::CULong)
test = alloca (\pStruct -> do
poke pStruct ( (fromIntegral 1)::CULong, (fromIntegral 1)::CULong )
)
Thanks for your help.
Marco
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://www.haskell.org/pipermail/beginners/attachments/20100206/b94d5a8d/attachment-0001.html
------------------------------
Message: 4
Date: Sat, 6 Feb 2010 22:26:38 +1000
From: Duncan Mortimer <[email protected]>
Subject: Re: [Haskell-beginners] Installing hmatrix on OS X
To: Lyndon Maydwell <[email protected]>
Cc: [email protected]
Message-ID:
<[email protected]>
Content-Type: text/plain; charset=ISO-8859-1
Hi All,
Following Heinrich's advice (thanks), I found the following worked:
in hmatrix.cabal:
change "build-type: Custom" to "build-type: Simple"
and at the end of hmatrix.cabal:
change "extra-libraries:" to "extra-libraries: gsl"
and
"extra-lib-dirs: " to "extra-lib-dirs: /opt/local/lib/"
Then at the command line run:
cabal --extra-include-dirs=/opt/local/include configure
followed by
cabal --extra-include-dirs=/opt/local/include install
I couldn't work out how to put the extra-include-dirs details into the
hmatrix.cabal file --- I kept getting the error "Warning:
hmatrix.cabal: Unknown fields: extra-include-dirs".
Anyway --- the above appears to have worked for me. I thought I'd
send it back to the list in the hopes that it helps someone else. And
if anyone can explain where "extra-include-dirs" should go in the
hmatrix.cabal file, please let me know! :)
best,
Duncan
On Sat, Feb 6, 2010 at 6:52 PM, Lyndon Maydwell <[email protected]> wrote:
> I'm having a similar error when trying to install HMatrix on OS X as
> well. Interested if anyone can find a solution.
>
> On Sat, Feb 6, 2010 at 11:25 AM, Duncan Mortimer <[email protected]> wrote:
>> Hi all,
>>
>> I'm trying to install the easyVision library on OS X, following the
>> notes at http://mit.edu/harold/Public/easyVisionNotes.html.
>>
>> However, despite a few hours web trawling and hacking away with
>> various cabal options, I can't get "hmatrix" to install. I'm using OS
>> X 10.5.8 with GHC 6.10.4. I installed gsl using macports, as
>> suggested in the notes above, but cabal doesn't seem to be able to
>> find it. The error I'm getting is:
>>
>> [13:22:35 dmorti hmatrix-0.8.2.0]$ cabal install hmatrix
>> Resolving dependencies...
>> [1 of 1] Compiling Main (
>> /var/folders/05/05Ltg9vxE+a1hR422nbuE++++TI/-Tmp-/hmatrix-0.8.2.05810/hmatrix-0.8.2.0/Setup.lhs,
>> /var/folders/05/05Ltg9vxE+a1hR422nbuE++++TI/-Tmp-/hmatrix-0.8.2.05810/hmatrix-0.8.2.0/dist/setup/Main.o
>> )
>> Linking
>> /var/folders/05/05Ltg9vxE+a1hR422nbuE++++TI/-Tmp-/hmatrix-0.8.2.05810/hmatrix-0.8.2.0/dist/setup/setup
>> ...
>> Configuring hmatrix-0.8.2.0...
>> Checking foreign libraries... FAIL
>> *** Sorry, I can't link GSL.
>> *** Please make sure that the appropriate -dev packages are installed.
>> *** You can also specify the required libraries using
>> *** cabal install hmatrix --configure-option=link:lib1,lib2,lib3,etc.
>> setup: Package hmatrix-0.8.2.0 can't be built on this system.
>> cabal: Error: some packages failed to install:
>> hmatrix-0.8.2.0 failed during the building phase. The exception was:
>> exit: ExitFailure 1
>>
>> It appears that others have also had this error, but have been able to
>> fix it up by including "--extra-lib-dirs" and "--extra-include-dirs"
>> options, or using "ld-options: -framework vecLib". I've tried both of
>> these approaches, but still get the same errors.
>>
>> Can anyone offer any suggestions?
>>
>> Thanks very much for your help,
>> Duncan Mortimer
>> _______________________________________________
>> Beginners mailing list
>> [email protected]
>> http://www.haskell.org/mailman/listinfo/beginners
>>
>
------------------------------
Message: 5
Date: Sat, 6 Feb 2010 22:31:54 +1000
From: Duncan Mortimer <[email protected]>
Subject: Re: [Haskell-beginners] Installing hmatrix on OS X
To: Lyndon Maydwell <[email protected]>
Cc: [email protected]
Message-ID:
<[email protected]>
Content-Type: text/plain; charset=ISO-8859-1
Ooops. Cancel that --- I didn't get any errors on running "cabal
install", and "hmatrix-0.8.2.0" is listed in my ghc-pkg list.
However, on attempting to run the tests listed on:
http://sites.google.com/site/wwwhmatrix/installation
i.e.: (in ghci):
> import Numeric.LinearAlgebra.Tests
> runTests 20
I get the error:
...
...
Loading package hmatrix-0.8.2.0 ... linking ... <interactive>:
unknown symbol `_zgemm_'
ghc: unable to load package `hmatrix-0.8.2.0'
Does anyone have any suggestions as to what's going on now?
Thanks,
Duncan
On Sat, Feb 6, 2010 at 10:26 PM, Duncan Mortimer <[email protected]> wrote:
> Hi All,
>
> Following Heinrich's advice (thanks), I found the following worked:
>
> in hmatrix.cabal:
>
> change "build-type: Custom" to "build-type: Simple"
>
> and at the end of hmatrix.cabal:
>
> change "extra-libraries:" to "extra-libraries: gsl"
> and
> "extra-lib-dirs: " to "extra-lib-dirs: /opt/local/lib/"
>
> Then at the command line run:
>
> cabal --extra-include-dirs=/opt/local/include configure
>
> followed by
>
> cabal --extra-include-dirs=/opt/local/include install
>
> I couldn't work out how to put the extra-include-dirs details into the
> hmatrix.cabal file --- I kept getting the error "Warning:
> hmatrix.cabal: Unknown fields: extra-include-dirs".
>
> Anyway --- the above appears to have worked for me. I thought I'd
> send it back to the list in the hopes that it helps someone else. And
> if anyone can explain where "extra-include-dirs" should go in the
> hmatrix.cabal file, please let me know! :)
>
> best,
> Duncan
>
>
> On Sat, Feb 6, 2010 at 6:52 PM, Lyndon Maydwell <[email protected]> wrote:
>> I'm having a similar error when trying to install HMatrix on OS X as
>> well. Interested if anyone can find a solution.
>>
>> On Sat, Feb 6, 2010 at 11:25 AM, Duncan Mortimer <[email protected]> wrote:
>>> Hi all,
>>>
>>> I'm trying to install the easyVision library on OS X, following the
>>> notes at http://mit.edu/harold/Public/easyVisionNotes.html.
>>>
>>> However, despite a few hours web trawling and hacking away with
>>> various cabal options, I can't get "hmatrix" to install. I'm using OS
>>> X 10.5.8 with GHC 6.10.4. I installed gsl using macports, as
>>> suggested in the notes above, but cabal doesn't seem to be able to
>>> find it. The error I'm getting is:
>>>
>>> [13:22:35 dmorti hmatrix-0.8.2.0]$ cabal install hmatrix
>>> Resolving dependencies...
>>> [1 of 1] Compiling Main (
>>> /var/folders/05/05Ltg9vxE+a1hR422nbuE++++TI/-Tmp-/hmatrix-0.8.2.05810/hmatrix-0.8.2.0/Setup.lhs,
>>> /var/folders/05/05Ltg9vxE+a1hR422nbuE++++TI/-Tmp-/hmatrix-0.8.2.05810/hmatrix-0.8.2.0/dist/setup/Main.o
>>> )
>>> Linking
>>> /var/folders/05/05Ltg9vxE+a1hR422nbuE++++TI/-Tmp-/hmatrix-0.8.2.05810/hmatrix-0.8.2.0/dist/setup/setup
>>> ...
>>> Configuring hmatrix-0.8.2.0...
>>> Checking foreign libraries... FAIL
>>> *** Sorry, I can't link GSL.
>>> *** Please make sure that the appropriate -dev packages are installed.
>>> *** You can also specify the required libraries using
>>> *** cabal install hmatrix --configure-option=link:lib1,lib2,lib3,etc.
>>> setup: Package hmatrix-0.8.2.0 can't be built on this system.
>>> cabal: Error: some packages failed to install:
>>> hmatrix-0.8.2.0 failed during the building phase. The exception was:
>>> exit: ExitFailure 1
>>>
>>> It appears that others have also had this error, but have been able to
>>> fix it up by including "--extra-lib-dirs" and "--extra-include-dirs"
>>> options, or using "ld-options: -framework vecLib". I've tried both of
>>> these approaches, but still get the same errors.
>>>
>>> Can anyone offer any suggestions?
>>>
>>> Thanks very much for your help,
>>> Duncan Mortimer
>>> _______________________________________________
>>> Beginners mailing list
>>> [email protected]
>>> http://www.haskell.org/mailman/listinfo/beginners
>>>
>>
>
------------------------------
Message: 6
Date: Sat, 6 Feb 2010 08:18:44 -0500
From: Patrick LeBoutillier <[email protected]>
Subject: Re: [Haskell-beginners] Typeclass problems
To: [email protected]
Message-ID:
<[email protected]>
Content-Type: text/plain; charset=ISO-8859-1
Daniel,
Thanks a lot for the info! That's a subtlety I wasn't aware of.
Patrick
On Thu, Feb 4, 2010 at 5:37 PM, Daniel Fischer <[email protected]> wrote:
> Am Donnerstag 04 Februar 2010 23:14:33 schrieb Patrick LeBoutillier:
>> Hi all,
>>
>> I've written a small type class that is meant to behave a bit like Show:
>>
>> class Show a => Echo a where
>> echo :: a -> String
>> echoList :: [a] -> String
>> echoListSep :: a -> String
>>
>> echo = show
>> echoListSep _ = " "
>>
>> echoList [] = ""
>> echoList [x] = echo x
>> echoList (x:xs) = echo x ++ echoListSep x ++ echoList xs
>>
>>
>> instance Echo Char where
>> echo c = [c]
>> echoListSep _ = ""
>>
>> instance Echo a => Echo [a] where
>> echo = echoList
>>
>> instance Echo Int where
>> instance Echo Integer where
>> instance Echo Double where
>> instance Echo Float where
>>
>>
>> gen = map (const 1)
>>
>> f xs = map echo $ gen xs
>>
>>
>> However the code doesn't compile on the last line.
>> But it does compile if I replace 'echo' with 'show'.
>> What's missing to make my typeclass behave like Show and accept input
>> of any type (besides all the missing instances...)?
>> I looked at the code for Show but I didn't see anything that looked
>> "magical"...
>
> The "magic" is that Show is defined in the standard libraries.
> Read http://haskell.org/onlinereport/decls.html#sect4.3.4
> In particular, the last bullet point of
>
> "In situations where an ambiguous type is discovered, an ambiguous type
> variable, v, is defaultable if:
>
> * v appears only in constraints of the form C v, where C is a class,
> and
> * at least one of these classes is a numeric class, (that is, Num or a
> subclass of Num), and
> * all of these classes are defined in the Prelude or a standard library
> (Figures 6.2--6.3, pages -- show the numeric classes, and Figure 6.1, page
> , shows the classes defined in the Prelude.) "
>
>
> Now,
>
> gen xs :: Num a => [a]
>
> And you want to map echo over it, so we get the constraint
> (Num a, Echo a).
>
> Echo is not defined in the standard libraries, thus no defaulting takes
> place, you have to specify the type of 1 explicitly,
>
> map echo (gen xs :: [Int])
>
> should work.
>
> In real programmes, the type is often deducible from the context, so you'll
> be bitten by the defaulting restrictions less often then than at the ghci
> prompt.
>
> There's a proposal (or a couple) to change the defaulting rules in coming
> language standards, see e.g. http://hackage.haskell.org/trac/haskell-
> prime/wiki/Defaulting
>
>
>>
>>
>> Thanks,
>>
>> Patrick
>
> HTH,
> Daniel
>
>
--
=====================
Patrick LeBoutillier
Rosemère, Québec, Canada
------------------------------
Message: 7
Date: Thu, 4 Feb 2010 08:23:58 -0500
From: Dave Bayer <[email protected]>
Subject: Re: [Haskell-beginners] Re: Monadic composition without
throwing genericity under the bus?
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=utf-8
Thanks for all your answers.
Yes, Stephen explains exactly what I'm doing. I had been using a literate
preprocessor that could have been written in Basic, but didn't include
heredocs. It was very short, but I wanted something more idiomatic, so I stared
at everyone's parser tutorials, wondering about monadic -vs- applicative etc.
etc. The twin irritations of do notation everywhere, and ++ everywhere, pushed
me over the edge to try ShowS-valued monads, and I loved how the code looked.
Normally I accept wrappers on everything as just how one does business in
Haskell. As you say, to avoid undecidable type issues. Here I was struggling
for days to make the code as lean as possible, and I could almost get away
without wrappers.
I've been following the migration convention of ASCII for historic Prelude,
Unicode for generic version of same, so I didn't want to steal ° for this one
purpose; it should be categorical composition. I like the answer that m ° (->)
is simply something different, I shouldn't think of it as composition. I had
been using â for this, I'll probably go back to it.
For a simple parser tutorial, or my immediate application of munging text e.g.
literate preprocessor, ok to hardwire ShowS-valued monads. However, when one
does have to break down and go into do notation (e.g. to implement my heredocs
which steal the indentation from the closing EOF, and otherwise looks cleaner
with multiple parsing passes), it might be slicker to use a general (a â b)
type in place of ShowS. In fact, I believe one could do anything other parsers
do, this way, with the benefit of most expressions being composition not
requiring do-notation.
Anyhow, going further with monads returning (a â b) required me to make my
peace with this composition issue, so I thank each of you!
I will write up a tutorial on this form of parsing when I submit my literate
preprocessor to Cabal.
On Feb 4, 2010, at 6:25 AM, Stephen Tetley wrote:
> The parser has a type restricted return type - always a 'Hughes
> string' with efficient concatenation (ShowS :: String -> String)
> rather than some polymorphic answer (e.g a parse tree). For formatting
> it allows you to add text without consuming any:
>
> inserttext :: String -> Parser
> inserttext str = return (showString str)
>
> Or rewrite matched input:
>
> rewrite :: String -> String -> Parser
> rewrite inp out = string inp >> return (showString out)
>
> Or drop text, I presume this is what the place combinator does.
>
> Its a nice technique.
>
> On 4 February 2010 10:46, Heinrich Apfelmus <[email protected]> wrote:
>>
>> This looks intriguing! Can you elaborate on how this works?
>
------------------------------
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
End of Beginners Digest, Vol 20, Issue 12
*****************************************