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:  using parametrized monads and Prelude.>> (Thomas Davie)
   2. Re:  Defeating type inference (Philip Scott)
   3. Re:  Defeating type inference (Philip Scott)
   4. Re:  Lambda Functions (Matt R)
   5.  Module structure (Colin Paul Adams)
   6. Re:  Module structure (Chadda? Fouch?)
   7. Re:  Lambda Functions (Brent Yorgey)
   8. Re:  Module structure (Colin Paul Adams)
   9. Re:  Module structure (David Frey)
  10. Re:  Module structure (Colin Paul Adams)


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

Message: 1
Date: Fri, 27 Feb 2009 09:01:39 +0100
From: Thomas Davie <[email protected]>
Subject: Re: [Haskell-beginners] using parametrized monads and
        Prelude.>>
To: frea <[email protected]>
Cc: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes


On 27 Feb 2009, at 01:06, frea wrote:

> Hello,
> I would like to create few functions which use parametrized monads
> (defined as in 
> http://computationalthoughts.blogspot.com/2009/02/comment-on-parameterized-monads.html
> ) and export their functionality outside a module and use them in a do
> statement.
> For example three exported funtions :
>
> func1 num = do
>        x <- get
>        put (show (x + num))
>
> func2 num = do
>        x <- get
>        put (((read x)::Int) + num)
>
> execWith0 actions = runState actions 0
>
> And in an another module, which has Prelude imported :
>
> k = execWith0 ( do
>                func1 10
>                func2 5)
>
> Unfortunately this doesn't compile as in the second module >> is
> different than in PMonad. Is there any way which I could make it work?

The definition of (>>) is not determined by which module you're in,  
instead by what the types it is operating on are.  Check which monad  
these functions really are in, and you'll probably find your error.

Bob


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

Message: 2
Date: Thu, 26 Feb 2009 11:21:31 +0000
From: Philip Scott <[email protected]>
Subject: Re: [Haskell-beginners] Defeating type inference
To: Alexander Dunlap <[email protected]>
Cc: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed

Hi Alex,
> The problem is that when you go fro
>> months = range (Jan,Dec) : months
>> realmonths = concat months
>>     
> to
>> months = concat (range (Jan,Dec) : months)
>>     
> you're not just collapsing the two functions, you're changing the
> definition (and type!) of "months" which you referred to within the
> months function. Since months is a recursive function, you can't
> necessary fold in the definition of realmonths because you want the
> recursion to apply to the original months, not the original
> realmonths.
>
>   
Of course, why didn't I see that :) I think I had managed to get my head 
into its own recursive loop.. I think I might have to replace my evening 
glass or three of wine with some Red Bull while I am getting my mind 
around this stuff.
> As you suspected, there are better and simpler ways of doing this
> available, although your way is good for getting the hang of
> recursion, even though experienced haskellers really don't use
> recursion all that much. (Most prefer to use functions that
> encapsulate recursion *patterns* such as map, filter, folds and many
> more.) 
>   
Thank you very much for you help and suggestions, I shall bear them in mind.

- Philip


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

Message: 3
Date: Thu, 26 Feb 2009 11:26:23 +0000
From: Philip Scott <[email protected]>
Subject: Re: [Haskell-beginners] Defeating type inference
To: Daniel Fischer <[email protected]>
Cc: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed

Hi ho,
> One more improvement, include also Enum among the derived classes, then you 
> can write
>
> months = cycle [Jan .. Dec]
>
> Oh, and cycle is also exported from the Prelude, so it's not necessary to 
> import Data.List for that (though you will probably want to imoprt it 
> anyway).
>   

Ohh so many little tasty titbits of Haskell - I was trying for ages to 
get the '..' operator to work. I guess I will start to know where to 
look for these guys as time goes on.

Cheers,

Philip


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

Message: 4
Date: Fri, 27 Feb 2009 08:41:36 +0000
From: Matt R <[email protected]>
Subject: Re: [Haskell-beginners] Lambda Functions
To: Andrew Wagner <[email protected]>
Cc: [email protected]
Message-ID:
        <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1

On 26/02/2009, Andrew Wagner <[email protected]> wrote:
> Excellent list. It seems like every time I hear about a problem with the
> MMR, I go "wow, how come I never ran across that? oh yeah, because I write
> type signatures..."

Certainly. Still, it seems relatively easy to bump into it when
tinkering on ghci.

Out of interest, what are the disadvantages to blanket turning off the
restriction?

-- Matt


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

Message: 5
Date: Fri, 27 Feb 2009 16:36:09 +0000
From: Colin Paul Adams <[email protected]>
Subject: [Haskell-beginners] Module structure
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii

If I want to write part of the code for my program as a library, and
so put those modules into a hierarchical module structure (with the
non-library code in no module), do I have to structure the directories
in a special way to get the module search to work?
-- 
Colin Adams
Preston Lancashire


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

Message: 6
Date: Fri, 27 Feb 2009 18:26:51 +0100
From: Chadda? Fouch? <[email protected]>
Subject: Re: [Haskell-beginners] Module structure
To: Colin Paul Adams <[email protected]>
Cc: [email protected]
Message-ID:
        <[email protected]>
Content-Type: text/plain; charset=UTF-8

On Fri, Feb 27, 2009 at 5:36 PM, Colin Paul Adams
<[email protected]> wrote:
> If I want to write part of the code for my program as a library, and
> so put those modules into a hierarchical module structure (with the
> non-library code in no module), do I have to structure the directories
> in a special way to get the module search to work?

Yes, module My.Pretty.Little.Module must be in file
"My/Pretty/Little/Module.hs" in one of the root directories (which can
be specified on the command line to ghc, or in the .cabal file if you
use an unusual directory structure).
Note that this only apply before compiling, the executable is independent.

-- 
Jedaï


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

Message: 7
Date: Fri, 27 Feb 2009 12:31:22 -0500
From: Brent Yorgey <[email protected]>
Subject: Re: [Haskell-beginners] Lambda Functions
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii

The only disadvantage is that some things you might expect to be
constants will actually get recomputed every time they are used. For
example, suppose you define

  foo = very expensive computation involving a bunch of numbers

You might think that foo will get computed just once, the first time
it is needed.  However, if foo ends up with a polymorphic type, like,
say

  foo :: Num a => a

then it is not actually a constant, but a function which takes a Num
dictionary (i.e. a record of the Num methods) as an argument.  So it
will be recomputed every time it is used, since it might have
different values for different types.

Now, you might wonder why this is such a big deal.  The answer is: it
isn't.  I have the MR automatically turned off in my .ghci file, and
I've never missed it.  Furthermore, the monomorphism restriction will
be removed in the next version of the Haskell language standard.

-Brent

On Fri, Feb 27, 2009 at 08:41:36AM +0000, Matt R wrote:
> On 26/02/2009, Andrew Wagner <[email protected]> wrote:
> > Excellent list. It seems like every time I hear about a problem with the
> > MMR, I go "wow, how come I never ran across that? oh yeah, because I write
> > type signatures..."
> 
> Certainly. Still, it seems relatively easy to bump into it when
> tinkering on ghci.
> 
> Out of interest, what are the disadvantages to blanket turning off the
> restriction?
> 
> -- Matt
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners


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

Message: 8
Date: Fri, 27 Feb 2009 17:39:26 +0000
From: Colin Paul Adams <[email protected]>
Subject: Re: [Haskell-beginners] Module structure
To: Chadda? Fouch? <[email protected]>
Cc: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=iso-8859-1

>>>>> "Chaddaï" == Chaddaï Fouché <[email protected]> writes:

    Chaddaï> On Fri, Feb 27, 2009 at 5:36 PM, Colin Paul Adams
    Chaddaï> <[email protected]> wrote:
    >> If I want to write part of the code for my program as a
    >> library, and so put those modules into a hierarchical module
    >> structure (with the non-library code in no module), do I have
    >> to structure the directories in a special way to get the module
    >> search to work?

    Chaddaï> Yes, module My.Pretty.Little.Module must be in file
    Chaddaï> "My/Pretty/Little/Module.hs" in one of the root
    Chaddaï> directories (which can be specified on the command line
    Chaddaï> to ghc, or in the .cabal file if you use an unusual
    Chaddaï> directory structure).  Note that this only apply before
    Chaddaï> compiling, the executable is independent.

Thank you.
Where do I find out what the root directories are? Is mt project
directory one of them?
-- 
Colin Adams
Preston Lancashire


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

Message: 9
Date: Fri, 27 Feb 2009 10:55:50 -0800
From: David Frey <[email protected]>
Subject: Re: [Haskell-beginners] Module structure
To: [email protected]
Message-ID: <617ad6e73214998fc481904b1cdbd...@localhost>
Content-Type: text/plain; charset="UTF-8"

On Fri, 27 Feb 2009 18:26:51 +0100, Chaddaï Fouché
<[email protected]> wrote:
> On Fri, Feb 27, 2009 at 5:36 PM, Colin Paul Adams
> <[email protected]> wrote:
>> If I want to write part of the code for my program as a library, and
>> so put those modules into a hierarchical module structure (with the
>> non-library code in no module), do I have to structure the directories
>> in a special way to get the module search to work?
> 
> Yes, module My.Pretty.Little.Module must be in file
> "My/Pretty/Little/Module.hs" in one of the root directories (which can
> be specified on the command line to ghc, or in the .cabal file if you
> use an unusual directory structure).
> Note that this only apply before compiling, the executable is
independent.

This last line sounds a bit fishy to me.  I think what would happen here is
that you would create a separate module, but when your application is
linked, any code that is used from that module would be compiled and
included into your binary.  I suspect that what Colin may have been looking
for are instructions on how to create a standalone library that his
application can dynamically link to.  I'm curious about this as well.


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

Message: 10
Date: Fri, 27 Feb 2009 19:04:25 +0000
From: Colin Paul Adams <[email protected]>
Subject: Re: [Haskell-beginners] Module structure
To: David Frey <[email protected]>
Cc: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii

>>>>> "David" == David Frey <[email protected]> writes:

    David> I suspect that what Colin may have been
    David> looking for are instructions on how to create a standalone
    David> library that his application can dynamically link to.  I'm
    David> curious about this as well.

No, I was only interested in how to structure the library on disk.
-- 
Colin Adams
Preston Lancashire


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

_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners


End of Beginners Digest, Vol 8, Issue 28
****************************************

Reply via email to