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: string instead of char (Michael Snoyman)
2. Advantage to installing Hugs with GHC? (John Velman)
3. Re: Advantage to installing Hugs with GHC? (Brent Yorgey)
4. Re: Advantage to installing Hugs with GHC? (Heinrich Apfelmus)
5. Re: Re: Advantage to installing Hugs with GHC? (John Velman)
6. Re: string instead of char (Joe Van Dyk)
7. Compiling C that calls Haskell with GCC (John Velman)
8. (ab)use compiler optimization (Martin Hofmann)
9. Re: (ab)use compiler optimization (Heinrich Apfelmus)
----------------------------------------------------------------------
Message: 1
Date: Sun, 4 Oct 2009 21:14:05 +0200
From: Michael Snoyman <[email protected]>
Subject: Re: [Haskell-beginners] string instead of char
To: Robert Ziemba <[email protected]>
Cc: [email protected]
Message-ID:
<[email protected]>
Content-Type: text/plain; charset="utf-8"
Or instead of ['a', 'e', 'i', 'o', 'u'] use "aeiou". However, I think the
case statement, while my verbose, is also clearer. But that's purely a style
choice.
Michael
On Sun, Oct 4, 2009 at 8:55 PM, Robert Ziemba <[email protected]> wrote:
> You can also do something like this instead of the case statement (this is
> using GHCI).
> Prelude> let exclude = ['a', 'e', 'i', 'o', 'u']
> Prelude> let f excl letter | letter `elem` excl = 'x' | otherwise = letter
> Prelude> map (f exclude) "hello"
> "hxllx"
>
> Rob Ziemba
>
> On Sun, Oct 4, 2009 at 9:10 AM, Colin Paul Adams <[email protected]
> > wrote:
>
>> >>>>> "John" == John Moore <[email protected]> writes:
>>
>> John> Hi, I am now writing a function that replaces vowels with
>> John> the letter x. eg.put in a string "help" and out comes hxlp.
>> John> I tried this:
>>
>> John> f x = case x of
>>
>> John> {'a' -> 'x';'e' -> 'x';'i' -> 'x';'o' -> 'x';'u' ->
>> John> 'x';_ -> x}
>>
>> John> but this wont work on strings, only on the individual
>> John> letters. Any direction would be very welcome.
>>
>> You need to call
>>
>> map f "whatever"
>>
>> where f is your function for replacing a character (as above).
>> --
>> Colin Adams
>> Preston Lancashire
>> _______________________________________________
>> Beginners mailing list
>> [email protected]
>> http://www.haskell.org/mailman/listinfo/beginners
>>
>
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://www.haskell.org/pipermail/beginners/attachments/20091004/8bdcbff0/attachment-0001.html
------------------------------
Message: 2
Date: Sun, 4 Oct 2009 14:53:44 -0700
From: John Velman <[email protected]>
Subject: [Haskell-beginners] Advantage to installing Hugs with GHC?
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii
My machine is an iMac running Leopard, 10.5.8. I've installed GHC from
the haskell-platform-..(Leopard/x86) disk image. Ghci works fine as far as
I can tell.
Is there any particular advantage to also installing Hugs?
Thanks,
John Velman
------------------------------
Message: 3
Date: Sun, 4 Oct 2009 21:51:22 -0400
From: Brent Yorgey <[email protected]>
Subject: Re: [Haskell-beginners] Advantage to installing Hugs with
GHC?
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii
On Sun, Oct 04, 2009 at 02:53:44PM -0700, John Velman wrote:
>
> My machine is an iMac running Leopard, 10.5.8. I've installed GHC from
> the haskell-platform-..(Leopard/x86) disk image. Ghci works fine as far as
> I can tell.
>
> Is there any particular advantage to also installing Hugs?
Not really, unless (say) you are following some tutorial that specifically uses
it.
-Brent
------------------------------
Message: 4
Date: Mon, 05 Oct 2009 11:40:13 +0200
From: Heinrich Apfelmus <[email protected]>
Subject: [Haskell-beginners] Re: Advantage to installing Hugs with
GHC?
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1
Brent Yorgey wrote:
> On Sun, Oct 04, 2009 at 02:53:44PM -0700, John Velman wrote:
>> My machine is an iMac running Leopard, 10.5.8. I've installed GHC from
>> the haskell-platform-..(Leopard/x86) disk image. Ghci works fine as far as
>> I can tell.
>>
>> Is there any particular advantage to also installing Hugs?
>
> Not really, unless (say) you are following some tutorial that specifically
> uses it.
Well, Hugs does start much faster than ghci on my machine, but that's
about the only advantage. :)
Regards,
apfelmus
--
http://apfelmus.nfshost.com
------------------------------
Message: 5
Date: Mon, 5 Oct 2009 08:15:16 -0700
From: John Velman <[email protected]>
Subject: Re: [Haskell-beginners] Re: Advantage to installing Hugs with
GHC?
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii
On Mon, Oct 05, 2009 at 11:40:13AM +0200, Heinrich Apfelmus wrote:
> Brent Yorgey wrote:
> > On Sun, Oct 04, 2009 at 02:53:44PM -0700, John Velman wrote:
> >> My machine is an iMac running Leopard, 10.5.8. I've installed GHC from
> >> the haskell-platform-..(Leopard/x86) disk image. Ghci works fine as far as
> >> I can tell.
> >>
> >> Is there any particular advantage to also installing Hugs?
> >
> > Not really, unless (say) you are following some tutorial that specifically
> > uses it.
>
> Well, Hugs does start much faster than ghci on my machine, but that's
> about the only advantage. :)
>
>
> Regards,
> apfelmus
>
Thanks -- I can't notice any delay when starting ghci (I didn't always have
a fast machine!).
Also, I guess if something in a tutorial really depends on Hugs, it would
be something that I really don't need to know (unless I plan on using
Hugs,that is).
I'll skip installing Hugs.
Thanks to both.
John Velman
> --
> http://apfelmus.nfshost.com
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
------------------------------
Message: 6
Date: Mon, 5 Oct 2009 11:24:43 -0700
From: Joe Van Dyk <[email protected]>
Subject: Re: [Haskell-beginners] string instead of char
Cc: [email protected]
Message-ID:
<[email protected]>
Content-Type: text/plain; charset=UTF-8
How about instead:
devowelize input | elem input "abcde" = 'x'
devowelize input = input
Not sure if pattern matching is appropriate here.
On Sun, Oct 4, 2009 at 12:14 PM, Michael Snoyman <[email protected]> wrote:
> Or instead of ['a', 'e', 'i', 'o', 'u'] use "aeiou". However, I think the
> case statement, while my verbose, is also clearer. But that's purely a style
> choice.
>
> Michael
>
> On Sun, Oct 4, 2009 at 8:55 PM, Robert Ziemba <[email protected]> wrote:
>>
>> You can also do something like this instead of the case statement (this is
>> using GHCI).
>> Prelude> let exclude = ['a', 'e', 'i', 'o', 'u']
>> Prelude> let f excl letter | letter `elem` excl = 'x' | otherwise = letter
>> Prelude> map (f exclude) "hello"
>> "hxllx"
>> Rob Ziemba
>> On Sun, Oct 4, 2009 at 9:10 AM, Colin Paul Adams
>> <[email protected]> wrote:
>>>
>>> >>>>> "John" == John Moore <[email protected]> writes:
>>>
>>> Â Â John> Hi, I am now writing a function that replaces vowels with
>>> Â Â John> the letter x. Â eg.put in a string "help" and out comes hxlp.
>>> Â Â John> I tried this:
>>>
>>> Â Â John> f x = case x of
>>>
>>> Â Â John> Â Â Â {'a' -> 'x';'e' -> 'x';'i' -> 'x';'o' -> 'x';'u' ->
>>> Â Â John> 'x';_ -> x}
>>>
>>> Â Â John> but this wont work on strings, only on the individual
>>> Â Â John> letters. Any direction would be very welcome.
>>>
>>> You need to call
>>>
>>> map f "whatever"
>>>
>>> where f is your function for replacing a character (as above).
>>> --
>>> Colin Adams
>>> Preston Lancashire
>>> _______________________________________________
>>> Beginners mailing list
>>> [email protected]
>>> http://www.haskell.org/mailman/listinfo/beginners
>>
>>
>> _______________________________________________
>> Beginners mailing list
>> [email protected]
>> http://www.haskell.org/mailman/listinfo/beginners
>>
>
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>
>
--
Joe Van Dyk
http://fixieconsulting.com
------------------------------
Message: 7
Date: Mon, 5 Oct 2009 15:41:38 -0700
From: John Velman <[email protected]>
Subject: [Haskell-beginners] Compiling C that calls Haskell with GCC
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii
More specifically, I want to link a haskell .o file into a project I create
on OS X using Xcode, but the answer to the gcc question should do it.
I've followed the simple "calling haskell from C" example from HaskellWiki,
and it works as advertised when compiled as advertised with gcc.
However, I'm looking toward writing OS X programs with Xcode and the
standard Mac interface, calling some functions written in Haskell.
Consequently, I want to compile and link using the mac Xcode IDE, which
uses gcc.
Seems like the thing that GHC puts in must be include .h files and
libraries. But which ones?
I think I ran across the answer to this in my browsing, but can't find it
again. Can someone point me in the right direction?
Thanks,
John Velman
------------------------------
Message: 8
Date: Fri, 09 Oct 2009 09:45:27 +0200
From: Martin Hofmann <[email protected]>
Subject: [Haskell-beginners] (ab)use compiler optimization
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain
Hello,
To analyse, test, and debug my system I use a WriterT for logging. The
log file created can be quite large and a lot of 'Log' is created in
memory, too.
I thought, that maybe I can (ab)use the compiler to switch logging on
and off as needed before compiling. I tried to either always return an
empty Log when running the WriterT, or just always ignore logging
depending on a constant and hoped GHC to optimize the logging away.
_NOLOGGING = True
runWT :: (Monad m) => (WriterT Log m a) -> m (a, Log)
runWT m
| _NOLOGGING = runWriterT m empty >>= \(a,_) -> return (a,emptyLog )
| otherwise = runWriterT m emptyLog
logging :: Message -> WriterT Log m ()
logging msg = if _NOLOGGING then return () else tell msg
However, according to the heap profile there is still a lot of 'Log' in
the memory. So, is this possible this way at all and if not, is there
another (apart from removing all logging by hand).
Thanks
------------------------------
Message: 9
Date: Fri, 09 Oct 2009 13:10:28 +0200
From: Heinrich Apfelmus <[email protected]>
Subject: [Haskell-beginners] Re: (ab)use compiler optimization
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-15
Martin Hofmann wrote:
> I thought, that maybe I can (ab)use the compiler to switch logging on
> and off as needed before compiling. I tried to either always return an
> empty Log when running the WriterT, or just always ignore logging
> depending on a constant and hoped GHC to optimize the logging away.
>
>
> _NOLOGGING = True
>
> runWT :: (Monad m) => (WriterT Log m a) -> m (a, Log)
> runWT m
> | _NOLOGGING = runWriterT m empty >>= \(a,_) -> return (a,emptyLog )
> | otherwise = runWriterT m emptyLog
>
> logging :: Message -> WriterT Log m ()
> logging msg = if _NOLOGGING then return () else tell msg
>
>
> However, according to the heap profile there is still a lot of 'Log' in
> the memory. So, is this possible this way at all and if not, is there
> another (apart from removing all logging by hand).
Most likely, the WriterT monad is still constructing a log, except that
it now looks like
emptyLog `mappend` emptyLog `mappend` ... etc.
Of course, this is equal to emptyLog but it's never evaluated and
these huge expressions are eating up memory.
I think that importing WriterT from Control.Monad.Writer.Strict should
solve the problem. With that, you can revert to
runWT = runWriterT
as well, only logging needs to be implemented as you did.
Another method, which is guaranteed to work, is to implement a minuscule
custom logging monad like this:
module Logger where
type Logger m a = WriterT Log m a
runLogger = runWriterT
logging = tell
and replace it with
module MockLogger where
type Logger m a = m a
runLogger = fmap $ \a -> (a,emptyLog)
logging = const $ return ()
when you don't want to log anything.
Regards,
apfelmus
--
http://apfelmus.nfshost.com
------------------------------
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
End of Beginners Digest, Vol 16, Issue 3
****************************************