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.  performance issues (Sunil S Nandihalli)
   2. Re:  performance issues (Daniel Fischer)
   3. Re:  some Data.Map questions (David McBride)
   4. Re:  Where/Let clauses and subexpression
      repetition/memoization (Tom Murphy)
   5. Re:  Where/Let clauses and subexpression
      repetition/memoization (Brent Yorgey)
   6. Re:  Where/Let clauses and subexpression
      repetition/memoization (Brandon Allbery)
   7.  Could someone tell me where to find this example from the
      HaskellWiki? (Michael Litchard)
   8. Re:  Question: Data Type for user selection (Hartmut)


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

Message: 1
Date: Fri, 19 Aug 2011 15:32:30 +0530
From: Sunil S Nandihalli <sunil.nandiha...@gmail.com>
Subject: [Haskell-beginners] performance issues
To: beginners@haskell.org
Message-ID:
        <cap0fd731bd9npaabp4poxztk48uufsi1yxzmthwaksnl91r...@mail.gmail.com>
Content-Type: text/plain; charset=UTF-8

Hello everybody,
 I am a newbie to haskell. I was wondering if there are things I need
to do to make the following code faster. I have tried changing the
Integer to Int but did not help much..

https://gist.github.com/c1ee2d6397cd5b28ade5

Thanks in advance.
Sunil.



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

Message: 2
Date: Fri, 19 Aug 2011 12:25:34 +0200
From: Daniel Fischer <daniel.is.fisc...@googlemail.com>
Subject: Re: [Haskell-beginners] performance issues
To: beginners@haskell.org
Message-ID: <201108191225.34385.daniel.is.fisc...@googlemail.com>
Content-Type: Text/Plain;  charset="iso-8859-1"

On Friday 19 August 2011, 12:02:30, Sunil S Nandihalli wrote:
> Hello everybody,
>  I am a newbie to haskell. I was wondering if there are things I need
> to do to make the following code faster.

>From a short look, you'll probably need a faster prime generation, try a 
sieve of Eratosthenes, that's pretty fast. The rest looks okay

> I have tried changing the
> Integer to Int but did not help much..
> 
> https://gist.github.com/c1ee2d6397cd5b28ade5
> 
> Thanks in advance.
> Sunil.



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

Message: 3
Date: Fri, 19 Aug 2011 10:21:25 -0400
From: David McBride <dmcbr...@neondsl.com>
Subject: Re: [Haskell-beginners] some Data.Map questions
To: Dennis Raddle <dennis.rad...@gmail.com>
Cc: Haskell Beginners <beginners@haskell.org>
Message-ID:
        <CAN+Tr40Jy15YpgrczLBzfh8HZHvh9A=noo0d2sq+5yq47gm...@mail.gmail.com>
Content-Type: text/plain; charset=ISO-8859-1

Well, if you use that instruction type (you can call it whatever you
want), you should be able to use 'map' to

notes2instr :: Map Loc Note -> Map Loc Instr
dirs2instr :: Map Loc PlayDirection -> Map Loc Instr

which might simplify things a little from what I originally posted.  I
thought you might be able to use unionWithKey to combine, but that
would still be wrong because you cannot be sure what playdirection you
are in when you hit a specific note.

There is no function in Data.Map that will automatically tuple or
combine two different types of maps for you because there are so many
ways it could be done.  Even if it did, your requirements are specific
enough that you'll have to do the work yourself to get the right
answer.

On Fri, Aug 19, 2011 at 2:40 AM, Dennis Raddle <dennis.rad...@gmail.com> wrote:
> Hi David,
> This helps, for sure. I wondered if any of the rich selection of
> functions in Data.Map could be used, such as union. To perform a union
> on two maps, their elements must have the same type. From this one
> concludes that a type unifying Note's and PlayDirection's is
> necessary, which is what you have done in Instruction.
>
> On Thu, Aug 18, 2011 at 8:46 PM, David McBride <dmcbr...@neondsl.com> wrote:
>> Maybe something like this:
>>
>> instance Eq Loc where
>> ?a == b = ...
>> instance Ord Loc where
>> ?compare a b = ...
>>
>> data Instruction = InstrNote (Loc, Note) | InstrPD (Loc, PlayDirection)
>>
>> write a function that will combine the notes and playdirections into
>> one list of everything sequentially.
>>
>> combineNotesDirs :: [(Loc,Note)] -> [(Loc,PlayDirection)] -> [Instruction]
>> combineNotesDirs [] [] = []
>> combineNotesDirs [] (d:ds) = undefined --you can figure this out
>> combineNotesDirs (n:ns) [] = undefined
>> combineNotesDirs notes@(n:ns) dirs@(d:ds)
>> ?| fst d <= fst n = InstrPD d : (zipNotesDirs notes ds)
>> ?| otherwise ? ? ?= InstrNote n : (zipNotesDirs ns dirs)
>>
>> Then loop over that and store them as a map. ?Traverse the list, keep
>> track of the playdirection at each entry, and then accumulate the
>> current direction and note at each note entry into a new map.
>>
>> instructionlist2map :: [Instruction] -> Map Loc (Note, PlayDirection)
>>
>> I'm sure this could be cleaned up a bit, but is that sort of what you
>> were looking for?
>>
>
> _______________________________________________
> Beginners mailing list
> Beginners@haskell.org
> http://www.haskell.org/mailman/listinfo/beginners
>



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

Message: 4
Date: Fri, 19 Aug 2011 09:43:13 -0700
From: Tom Murphy <amin...@gmail.com>
Subject: Re: [Haskell-beginners] Where/Let clauses and subexpression
        repetition/memoization
To: Daniel Fischer <daniel.is.fisc...@googlemail.com>
Cc: beginners@haskell.org
Message-ID:
        <cao9q0tuvgghw+brznxcd+lrmoy3tsnv_blu87+c-0rqqhzs...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"

On Fri, Aug 19, 2011 at 2:52 AM, Daniel Fischer <
daniel.is.fisc...@googlemail.com> wrote:

> [...] In most cases, you'll get recomputation,
> but GHC does a bit of CSE, so in some cases it will compute only once and
> share the result (which may be a bad thing - that's a further reason for
> not doing too much CSE, sometimes sharing has catastrophic results).
>
>
This is a beginner's list, so I'll ask: what catastrophic result could it
have, if it's computing pure functions?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20110819/74e7ca31/attachment-0001.htm>

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

Message: 5
Date: Fri, 19 Aug 2011 13:41:36 -0400
From: Brent Yorgey <byor...@seas.upenn.edu>
Subject: Re: [Haskell-beginners] Where/Let clauses and subexpression
        repetition/memoization
To: beginners@haskell.org
Message-ID: <20110819174136.ga28...@seas.upenn.edu>
Content-Type: text/plain; charset=us-ascii

On Fri, Aug 19, 2011 at 09:43:13AM -0700, Tom Murphy wrote:
> On Fri, Aug 19, 2011 at 2:52 AM, Daniel Fischer <
> daniel.is.fisc...@googlemail.com> wrote:
> 
> > [...] In most cases, you'll get recomputation,
> > but GHC does a bit of CSE, so in some cases it will compute only once and
> > share the result (which may be a bad thing - that's a further reason for
> > not doing too much CSE, sometimes sharing has catastrophic results).
> >
> >
> This is a beginner's list, so I'll ask: what catastrophic result could it
> have, if it's computing pure functions?

It cannot change the meaning of a program.  But it can drastically
change the memory usage.  For example, consider

  (length [1..1000000], sum [1..1000000])

vs.

  let x = [1..1000000] in (length x, sum x)

The first expression needs only a constant amount of memory, since
each list can be incrementally generated and garbage collected  while
accumulating the length and sum.  In the second program, however, x
cannot be garbage collected while length is being computed, since x is
still being referred to by sum.  So at the point just after evaluating
length and before starting in on evaluation of sum, the entire
million-element list is in memory.

-Brent



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

Message: 6
Date: Fri, 19 Aug 2011 15:54:12 -0400
From: Brandon Allbery <allber...@gmail.com>
Subject: Re: [Haskell-beginners] Where/Let clauses and subexpression
        repetition/memoization
To: Tom Murphy <amin...@gmail.com>
Cc: beginners@haskell.org, Daniel Fischer
        <daniel.is.fisc...@googlemail.com>
Message-ID:
        <cakfcl4w4g0yl82sb6jlyfyopyhwjnzwmysa3x+km6vdbqlx...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

On Aug 19, 2011 12:44 PM, "Tom Murphy" <amin...@gmail.com> wrote:
> On Fri, Aug 19, 2011 at 2:52 AM, Daniel Fischer <
daniel.is.fisc...@googlemail.com> wrote:
>> [...] In most cases, you'll get recomputation,
>> but GHC does a bit of CSE, so in some cases it will compute only once and
>> share the result (which may be a bad thing - that's a further reason for
>> not doing too much CSE, sometimes sharing has catastrophic results).
>
> This is a beginner's list, so I'll ask: what catastrophic result could it
have, if it's computing pure functions?

Catastrophic means nontermination, usually due to the stack or heap getting
blown out. The classic example of catastrophic CSE is one of the simplest:
computing the average of a list that won't fit in memory, such as
[1..100000000000]. CSE, manual or automatic, would hold the entire list in
memory, while manually fusing the sum and count operations over a fold runs
in constant memory. Last I heard, GHC still didn't detect even that simple
case, although it does handle some others.

-- 
...tabula non rasa. ++bsa
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20110819/994a1050/attachment-0001.htm>

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

Message: 7
Date: Fri, 19 Aug 2011 14:21:24 -0700
From: Michael Litchard <mich...@schmong.org>
Subject: [Haskell-beginners] Could someone tell me where to find this
        example from the HaskellWiki?
To: beginners@haskell.org
Message-ID:
        <caezekyq5ue6brwqpvwce2rsy3+r3aqonhcuqnzdf69af29q...@mail.gmail.com>
Content-Type: text/plain; charset=ISO-8859-1

I was looking at this
http://www.haskell.org/haskellwiki/GHC/Type_families

And I found this
http://darcs.haskell.org/testsuite/tests/ghc-regress/indexed-types/should_run/GMapAssoc.hs

Which would be very useful. if it wasn't a dead link.

Could someone mail me a copy, or a live url?



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

Message: 8
Date: Sat, 20 Aug 2011 00:03:59 +0200
From: Hartmut <hartmut0...@googlemail.com>
Subject: Re: [Haskell-beginners] Question: Data Type for user
        selection
To: beginners@haskell.org
Message-ID:
        <CAFz=thfbhg0a75f+pzqsu7oosdqd6jvjpansnmj8z8ghvpv...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"

All,
thank You All for your gentle help. Now I am a step further :-) But there
raises up the next question:
In the last line, I want the datatype MultiSelect being limited to a's which
are of type "ExtendedSelect x".
How can I add this contraint?
Hartmut

{-# LANGUAGE GADTs #-}

module SelectionCriterias2 where

data InclusiveOrExclusive = Inclusive | Exclusive

-- 1. BasicSelect ------------------------------------------
data BasicSelect a where
  NumSelect :: Num a => a->BasicSelect a
  ShowSelect :: Show a => a->BasicSelect a

-- examples:
x1 = NumSelect 10
x2 = ShowSelect "Hello"
x3 = NumSelect 120.1

-- 2. ExtendedSelect ---------------------------------------
data ExtendedSelect a = ExtendedSelect {
  basicSel :: BasicSelect a,
  inclOrExcl :: InclusiveOrExclusive
}

-- examples:
x1i :: ExtendedSelect Integer
x1i = ExtendedSelect { basicSel = x1, inclOrExcl = Inclusive }
x1e = ExtendedSelect { basicSel = x1, inclOrExcl = Exclusive }
x2i = ExtendedSelect { basicSel = x2, inclOrExcl = Inclusive }
x2e = ExtendedSelect { basicSel = x2, inclOrExcl = Exclusive }

-- Abbreviation/helper for the construction:
extsel :: BasicSelect a -> InclusiveOrExclusive -> ExtendedSelect a
extsel s ie = ExtendedSelect { basicSel = s, inclOrExcl = ie }

-- examples:
x3i = extsel x3 Inclusive
x3e = extsel x3 Exclusive

-- 3. MultiSelect -----------------------------------------
data MultiSelect a = EmptySel | SingleSel a | MultiSel [a]




On Wed, Aug 17, 2011 at 3:42 PM, Brent Yorgey <byor...@seas.upenn.edu>wrote:

> On Tue, Aug 16, 2011 at 04:44:15PM +0200, Ertugrul Soeylemez wrote:
> > Brent Yorgey <byor...@seas.upenn.edu> wrote:
> >
> > > > That's a bit of a contradiction, because you are using existentials
> > > > yourself in your GADT.
> > >
> > > No, he isn't.
> > >
> > >    data BasicSelect a where
> > >      SelectionNum :: Num a => a -> BasicSelect a
> > >      SelectionStr :: Show a => a -> BasicSelect a
> > >
> > > 'a' shows up in the result type of both constructors, so there is no
> > > existential quantification going on here.
> >
> > Oh, right.  How would one express this as an ADT?  Seems impossible to
> > me.
>
> You cannot, with just Haskell 2010.  Strangely, if you try this:
>
>  data BasicSelect a = Num a  => SelectionNum a
>                     | Show a => SelectionStr a
>
> you get this error (ghc 7.0.3):
>
>  Data constructor `SelectionNum' has existential type variables, or a
>  context
>    (Use -XExistentialQuantification or -XGADTs to allow this)
>  In the definition of data constructor `SelectionNum'
>  In the data type declaration for `BasicSelect'
>
> And enabling ExistentialQuantification makes the error go away!  So
> apparently the ExistentialQuantification flag also enables type class
> constraints on data constructors, even when no existential
> quantification is involved.  Odd.
>
> -Brent
>
> _______________________________________________
> 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/20110820/1bbcfe52/attachment.htm>

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

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


End of Beginners Digest, Vol 38, Issue 35
*****************************************

Reply via email to