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.  Trying to understand type families. (Michael Litchard)
   2. Re:  Trying to understand type families. (Brandon Allbery)
   3. Re:  Could someone tell me where to find this     example from
      the HaskellWiki? (Daniel Fischer)
   4. Re:  Could someone tell me where to find this example from
      the HaskellWiki? (Antoine Latter)
   5.  Trying to understand type families, continued...
      (Michael Litchard)
   6. Re:  Trying to understand type families,  continued...
      (Michael Litchard)
   7. Re:  performance issues (Sunil S Nandihalli)


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

Message: 1
Date: Fri, 19 Aug 2011 15:27:24 -0700
From: Michael Litchard <mich...@schmong.org>
Subject: [Haskell-beginners] Trying to understand type families.
To: beginners@haskell.org
Message-ID:
        <caezekyq-hdxrgkg8e2yjb30fyfaw8n37ehyftaedtne_rxl...@mail.gmail.com>
Content-Type: text/plain; charset=ISO-8859-1

For this question, I'll refer to
http://www.haskell.org/haskellwiki/GHC/Type_families#A_unit_instance

In particular this example


instance GMapKey () where
  data GMap () v           = GMapUnit (Maybe v)
  empty                    = GMapUnit Nothing
  lookup () (GMapUnit v)   = v
  insert () v (GMapUnit _) = GMapUnit $ Just v

Could someone explain what the () is doing?



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

Message: 2
Date: Fri, 19 Aug 2011 18:43:27 -0400
From: Brandon Allbery <allber...@gmail.com>
Subject: Re: [Haskell-beginners] Trying to understand type families.
To: Michael Litchard <mich...@schmong.org>
Cc: beginners@haskell.org
Message-ID:
        <cakfcl4v5zfoquvc_dorkbxbjn1jtnrxjfm2gwxxsvoru4yl...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

On Fri, Aug 19, 2011 at 18:27, Michael Litchard <mich...@schmong.org> wrote:

> instance GMapKey () where
>  data GMap () v           = GMapUnit (Maybe v)
>  empty                    = GMapUnit Nothing
>  lookup () (GMapUnit v)   = v
>  insert () v (GMapUnit _) = GMapUnit $ Just v
>
> Could someone explain what the () is doing?
>

Nothing?

It's a dummy example using Haskell's "unit type" () (a type with only one
non-bottom value, namely () itself; you can think of it as a nullary tuple
type).  In this case, it's being declared as an instance of GMapKey, so it
is used where a GMapKey is needed; that means the key type parameter of the
GMap type and the key value parameter of the lookup and insert functions.
 Since there's only one value, the corresponding map type GMapUnit is a
Maybe instead of a list or tree of some kind, since the single possible key
value is either present or absent.  This lets the example focus on the
instance machinery without complicating it with nontrivial lookup and insert
operations.

-- 
brandon s allbery                                      allber...@gmail.com
wandering unix systems administrator (available)     (412) 475-9364 vm/sms
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20110819/8c409a2c/attachment-0001.htm>

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

Message: 3
Date: Sat, 20 Aug 2011 00:49:15 +0200
From: Daniel Fischer <daniel.is.fisc...@googlemail.com>
Subject: Re: [Haskell-beginners] Could someone tell me where to find
        this    example from the HaskellWiki?
To: beginners@haskell.org
Message-ID: <201108200049.16074.daniel.is.fisc...@googlemail.com>
Content-Type: Text/Plain;  charset="iso-8859-1"

On Friday 19 August 2011, 23:21:24, Michael Litchard wrote:
> 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/shoul
> d_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?
> 

http://darcs.haskell.org/cgi-
bin/gitweb.cgi?p=testsuite.git;a=blob;f=tests/indexed-
types/should_run/GMapAssoc.hs

Or - at the moment -

https://github.com/ghc/testsuite/blob/2afdb7c5c3413d8d01230551cc7a4ed9c15893f3/tests/indexed-
types/should_run/GMapAssoc.hs

The GitHub one has commit hashes in the URL, so it might be preferable to 
just go to https://github.com/ghc/testsuite and click through from there 
(note there's no ghc-regress anymore).



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

Message: 4
Date: Fri, 19 Aug 2011 18:13:53 -0500
From: Antoine Latter <aslat...@gmail.com>
Subject: Re: [Haskell-beginners] Could someone tell me where to find
        this example from the HaskellWiki?
To: Daniel Fischer <daniel.is.fisc...@googlemail.com>
Cc: beginners@haskell.org
Message-ID:
        <CAKjSnQHfrnSJu==zv2muo9cypgomdrqgqpqvqt4rep_nr47...@mail.gmail.com>
Content-Type: text/plain; charset=UTF-8

On Fri, Aug 19, 2011 at 5:49 PM, Daniel Fischer
<daniel.is.fisc...@googlemail.com> wrote:
> On Friday 19 August 2011, 23:21:24, Michael Litchard wrote:
>> 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/shoul
>> d_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?
>>
>
> http://darcs.haskell.org/cgi-
> bin/gitweb.cgi?p=testsuite.git;a=blob;f=tests/indexed-
> types/should_run/GMapAssoc.hs
>
> Or - at the moment -
>
> https://github.com/ghc/testsuite/blob/2afdb7c5c3413d8d01230551cc7a4ed9c15893f3/tests/indexed-
> types/should_run/GMapAssoc.hs
>
> The GitHub one has commit hashes in the URL, so it might be preferable to
> just go to https://github.com/ghc/testsuite and click through from there
> (note there's no ghc-regress anymore).
>

You can also link to a file within the head of a branch:

https://github.com/ghc/testsuite/blob/master/tests/indexed-types/should_run/GMapAssoc.hs

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



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

Message: 5
Date: Fri, 19 Aug 2011 16:53:54 -0700
From: Michael Litchard <mich...@schmong.org>
Subject: [Haskell-beginners] Trying to understand type families,
        continued...
To: beginners@haskell.org
Message-ID:
        <caezekypht8xjsdg-f_b+vpstmwxq9vnntttwbwph41bv8_2...@mail.gmail.com>
Content-Type: text/plain; charset=ISO-8859-1

I'm playing around with type families, and using as a starting point,
this example:

class GMapKey k where
  data GMap k :: * -> *
  empty       :: GMap k v
  lookup      :: k -> GMap k v -> Maybe v
  insert      :: k -> v -> GMap k v -> GMap k v



Here's an instance that will lead to my question

instance GMapKey Int where
  data GMap Int v        = GMapInt (Data.IntMap.IntMap v)
  empty                  = GMapInt Data.IntMap.empty
  lookup k   (GMapInt m) = Data.IntMap.lookup k m
  insert k v (GMapInt m) = GMapInt (Data.IntMap.insert k v m)

Here is my experiment


> class PM m where
>    data ServerModel m :: * -> *
>    movetoPreProcess :: m -> FilePath -> IO ()

I want to write an instance for this. As GMap can have an Int with
some value v, I would like ServerModel to have a type I create (with
another data declaration, call it Foo v) with values I define.

Here's a little more detail for the sake of any explanation that might
come my way.

data ModelFoo a = ModelBar a
                | ModelBaz a

ModelFoo is the type I want to use with ServerModel. What would the
instance declaration look like? If ServerModel is defined within PM,
should ModelFoo be as well?



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

Message: 6
Date: Fri, 19 Aug 2011 17:50:22 -0700
From: Michael Litchard <mich...@schmong.org>
Subject: Re: [Haskell-beginners] Trying to understand type families,
        continued...
To: beginners@haskell.org
Message-ID:
        <CAEzeKYruuXUwbnDXQBJUfZP53POvw4tH8=ryZZMr=zybzfw...@mail.gmail.com>
Content-Type: text/plain; charset=ISO-8859-1

kmc from #haskell at freenode has told me this is a classic case of
"don't need no typeclass here". So I reckon I will take the approach
discussed in #haskell and abandon this design.

On Fri, Aug 19, 2011 at 4:53 PM, Michael Litchard <mich...@schmong.org> wrote:
> I'm playing around with type families, and using as a starting point,
> this example:
>
> class GMapKey k where
> ?data GMap k :: * -> *
> ?empty ? ? ? :: GMap k v
> ?lookup ? ? ?:: k -> GMap k v -> Maybe v
> ?insert ? ? ?:: k -> v -> GMap k v -> GMap k v
>
>
>
> Here's an instance that will lead to my question
>
> instance GMapKey Int where
> ?data GMap Int v ? ? ? ?= GMapInt (Data.IntMap.IntMap v)
> ?empty ? ? ? ? ? ? ? ? ?= GMapInt Data.IntMap.empty
> ?lookup k ? (GMapInt m) = Data.IntMap.lookup k m
> ?insert k v (GMapInt m) = GMapInt (Data.IntMap.insert k v m)
>
> Here is my experiment
>
>
>> class PM m where
>> ? ?data ServerModel m :: * -> *
>> ? ?movetoPreProcess :: m -> FilePath -> IO ()
>
> I want to write an instance for this. As GMap can have an Int with
> some value v, I would like ServerModel to have a type I create (with
> another data declaration, call it Foo v) with values I define.
>
> Here's a little more detail for the sake of any explanation that might
> come my way.
>
> data ModelFoo a = ModelBar a
> ? ? ? ? ? ? ? ?| ModelBaz a
>
> ModelFoo is the type I want to use with ServerModel. What would the
> instance declaration look like? If ServerModel is defined within PM,
> should ModelFoo be as well?
>



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

Message: 7
Date: Sat, 20 Aug 2011 14:20:00 +0530
From: Sunil S Nandihalli <sunil.nandiha...@gmail.com>
Subject: Re: [Haskell-beginners] performance issues
To: Daniel Fischer <daniel.is.fisc...@googlemail.com>
Cc: beginners@haskell.org
Message-ID:
        <CAP0FD73We_0aYjBQy7yV0H=9ApiCFSV=rw6acrgyl8gz5x9...@mail.gmail.com>
Content-Type: text/plain; charset=UTF-8

Thanks Daniel for your response. sieve of Eratosthenes has a very
elegant 1 line implementation thanks to laziness of haskell. Here is
what I came up with

primesSieve = 2:3:5:7:11:(filter (\x->(all (\p-> 0/=(mod x p))
(takeWhile (\p-> p*p<=x) primesSieve))) [13..])

But didn't seem to make a difference in performance. I had missed the
most obvious of things.... that is adding -O2 when compiling.. It gave
a speedup of close to 100 times which was very surprising! .. I
remember people setting some compiler options in the source file
itself. Can you shed some light on that?

Thanks,
Sunil.

On Fri, Aug 19, 2011 at 3:55 PM, Daniel Fischer
<daniel.is.fisc...@googlemail.com> wrote:
> 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.
>



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

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


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

Reply via email to