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:  Randomly selecting a data constructor (Yitzchak Gale)
   2. RE:  Randomly selecting a data constructor (Evgenij Merenkov)
   3.  Struct-like syntax issues (Sergey Mironov)
   4. Re:  Randomly selecting a data constructor (Brent Yorgey)
   5. Re:  Struct-like syntax issues (Brent Yorgey)
   6. Re:  Struct-like syntax issues (Rahul Kapoor)
   7. Re:  Struct-like syntax issues (Sergey Mironov)
   8.  Parsec 3.0 (Tim Perry)
   9. Re:  Parsec 3.0 (Daniel Fischer)
  10. Re:  Parsec 3.0 (Tim Perry)


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

Message: 1
Date: Sun, 14 Mar 2010 13:44:39 +0200
From: Yitzchak Gale <[email protected]>
Subject: Re: [Haskell-beginners] Randomly selecting a data constructor
To: Thomas Davie <[email protected]>
Cc: [email protected], Evgenij Merenkov <[email protected]>
Message-ID:
        <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1

Sorry, hit "Send" too soon:

>> data FigType = TR1 | TR2 | TR3 | TR4 | SQ | L1 | L2 | Z1 | Z2 | Z3 | Z4 |
>> NoFigure
>>                deriving (Enum, Bounded)
>> randomFigure :: IO FigType
>> randomFigure = toEnum <$> randomRIO
>>   (fromEnum (minBound :: FigType),
>>    fromEnum (maxBound :: FigType))

-Yitz


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

Message: 2
Date: Sun, 14 Mar 2010 12:53:41 +0000
From: Evgenij Merenkov <[email protected]>
Subject: RE: [Haskell-beginners] Randomly selecting a data constructor
To: <[email protected]>, <[email protected]>
Cc: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset="us-ascii"


Thank you. Didn't know that you can supply type directly to a function, like "f 
:: Type".

> From: [email protected]
> Date: Sun, 14 Mar 2010 13:44:39 +0200
> Subject: Re: [Haskell-beginners] Randomly selecting a data constructor
> To: [email protected]
> CC: [email protected]; [email protected]
> 
> Sorry, hit "Send" too soon:
> 
> >> data FigType = TR1 | TR2 | TR3 | TR4 | SQ | L1 | L2 | Z1 | Z2 | Z3 | Z4 |
> >> NoFigure
> >>                deriving (Enum, Bounded)
> >> randomFigure :: IO FigType
> >> randomFigure = toEnum <$> randomRIO
> >>   (fromEnum (minBound :: FigType),
> >>    fromEnum (maxBound :: FigType))
> 
> -Yitz
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
                                          
_________________________________________________________________
Your E-mail and More On-the-Go. Get Windows Live Hotmail Free.
https://signup.live.com/signup.aspx?id=60969
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
http://www.haskell.org/pipermail/beginners/attachments/20100314/2f197f4a/attachment-0001.html

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

Message: 3
Date: Sun, 14 Mar 2010 16:54:05 +0300
From: Sergey Mironov <[email protected]>
Subject: [Haskell-beginners] Struct-like syntax issues
To: [email protected]
Message-ID:
        <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1

Hi. I have definitions like

data MyData = MyData {
  a :: A,
  b :: B,
  c :: C,
  d :: D,
  ...
  z :: Z
  }

makeMyData :: A -> B -> MyData
makeMyData a' b' = MyData {
  a = a',
  b = b',
  c = default_c,
  ...
  z = default_z
  }

The goal is to use it like

myData1 = set_x x' . set_m m' . set_c c' $ makeMyData my_a my_b
myData2 = set_z z' . $ makeMyData my_a my_b


But. Writing set_* functions is a problem - MyData is loong and things like

set_d :: D -> MyData -> MyData
set_d val struct = struct{d=val}

will form that boilerplate.  Is there any _right_ way of doing it?

myData3 = (makeMyData my_a my_b) {x=x', z=z'}  approach is not working..

-- 
Thanks,
Sergey


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

Message: 4
Date: Sun, 14 Mar 2010 10:18:36 -0400
From: Brent Yorgey <[email protected]>
Subject: Re: [Haskell-beginners] Randomly selecting a data constructor
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii

On Sun, Mar 14, 2010 at 12:53:41PM +0000, Evgenij Merenkov wrote:
> 
> Thank you. Didn't know that you can supply type directly to a function, like 
> "f :: Type".

Yes, you can always put a type annotation on any value, it just tells
the compiler what type it should be.  In this case (minBound ::
FigType) is to help out the compiler's type inference, since otherwise
it would not know what type minBound should be (it could be any type
which is an instance of Bounded).

-Brent

> 
> > From: [email protected]
> > Date: Sun, 14 Mar 2010 13:44:39 +0200
> > Subject: Re: [Haskell-beginners] Randomly selecting a data constructor
> > To: [email protected]
> > CC: [email protected]; [email protected]
> > 
> > Sorry, hit "Send" too soon:
> > 
> > >> data FigType = TR1 | TR2 | TR3 | TR4 | SQ | L1 | L2 | Z1 | Z2 | Z3 | Z4 |
> > >> NoFigure
> > >>                deriving (Enum, Bounded)
> > >> randomFigure :: IO FigType
> > >> randomFigure = toEnum <$> randomRIO
> > >>   (fromEnum (minBound :: FigType),
> > >>    fromEnum (maxBound :: FigType))
> > 
> > -Yitz
> > _______________________________________________
> > Beginners mailing list
> > [email protected]
> > http://www.haskell.org/mailman/listinfo/beginners
>                                         
> _________________________________________________________________
> Your E-mail and More On-the-Go. Get Windows Live Hotmail Free.
> https://signup.live.com/signup.aspx?id=60969
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners



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

Message: 5
Date: Sun, 14 Mar 2010 10:22:13 -0400
From: Brent Yorgey <[email protected]>
Subject: Re: [Haskell-beginners] Struct-like syntax issues
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii

On Sun, Mar 14, 2010 at 04:54:05PM +0300, Sergey Mironov wrote:
> Hi. I have definitions like
> 
> data MyData = MyData {
>   a :: A,
>   b :: B,
>   c :: C,
>   d :: D,
>   ...
>   z :: Z
>   }
> 
> ...
>
> will form that boilerplate.  Is there any _right_ way of doing it?

Unfortunately there is no better way of doing it.  _However_, there
are several packages which can generate all this boilerplate code for
you!  Check out fclabels [1] or data-accessor [2].

-Brent

[1] http://hackage.haskell.org/package/fclabels
[2] http://hackage.haskell.org/package/data%2Daccessor


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

Message: 6
Date: Sun, 14 Mar 2010 09:58:30 -0500
From: Rahul Kapoor <[email protected]>
Subject: Re: [Haskell-beginners] Struct-like syntax issues
To: Sergey Mironov <[email protected]>
Cc: [email protected]
Message-ID:
        <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1

Using the record update syntax might make it a little nicer,
also the record syntax already provides getters and setters.

data MyData = MyData {
      a :: Int,
      b :: Int,
      c :: Int
    } deriving (Show)

def = MyData 1 2 3
-- or
-- def = MyData {a = 1, b = 2, c = 3}

makeMyData :: Int -> Int -> MyData
makeMyData a' b' = def { a = a', b = b'}

myData1 = (makeMyData 9 10) {a = 1}
myData2 = (makeMyData 11 12) {c = 12}

With syntax highlighting: http://haskell.pastebin.com/LxtLZCtL

HTH,
Rahul


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

Message: 7
Date: Sun, 14 Mar 2010 19:07:31 +0300
From: Sergey Mironov <[email protected]>
Subject: Re: [Haskell-beginners] Struct-like syntax issues
To: Rahul Kapoor <[email protected]>
Cc: [email protected]
Message-ID:
        <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1

2010/3/14 Rahul Kapoor <[email protected]>:
> Using the record update syntax might make it a little nicer,
> also the record syntax already provides getters and setters.
>
> data MyData = MyData {
>      a :: Int,
>      b :: Int,
>      c :: Int
>    } deriving (Show)
>
> def = MyData 1 2 3
> -- or
> -- def = MyData {a = 1, b = 2, c = 3}
>
> makeMyData :: Int -> Int -> MyData
> makeMyData a' b' = def { a = a', b = b'}
>
> myData1 = (makeMyData 9 10) {a = 1}
> myData2 = (makeMyData 11 12) {c = 12}
>
> With syntax highlighting: http://haskell.pastebin.com/LxtLZCtL
>
> HTH,
> Rahul
>

Thanks to all!

>
> myData3 = (makeMyData my_a my_b) {x=x', z=z'}  approach is not working..

I checked again - it works actually!

-- 
Thanks,
Sergey


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

Message: 8
Date: Mon, 15 Mar 2010 13:19:59 -0700 (PDT)
From: Tim Perry <[email protected]>
Subject: [Haskell-beginners] Parsec 3.0
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii

When I install Parsec using Cabal, I get version 2.1.0.1. Is there a way to get 
version 3.1? Or do I have to build it by hand?

Thanks,
Tim

C:\Documents and Settings\perry\haskell>cabal upgrade parsec --reinstall
Resolving dependencies...
Configuring parsec-2.1.0.1...
Preprocessing library parsec-2.1.0.1...
Building parsec-2.1.0.1...
....



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

Message: 9
Date: Mon, 15 Mar 2010 21:45:09 +0100
From: Daniel Fischer <[email protected]>
Subject: Re: [Haskell-beginners] Parsec 3.0
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain;  charset="iso-8859-1"

Am Montag 15 März 2010 21:19:59 schrieb Tim Perry:
> When I install Parsec using Cabal, I get version 2.1.0.1. Is there a way
> to get version 3.1? Or do I have to build it by hand?

cabal install parsec-3.1

If you want a version other than the default, you have to give the package 
name including the version number.

>
> Thanks,
> Tim



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

Message: 10
Date: Mon, 15 Mar 2010 15:06:27 -0700 (PDT)
From: Tim Perry <[email protected]>
Subject: Re: [Haskell-beginners] Parsec 3.0
To: Daniel Fischer <[email protected]>, [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=iso-8859-1

Thanks Daniel.

cabal install parsec-3.1.0 worked like a charm :)

--Tim




----- Original Message ----
From: Daniel Fischer <[email protected]>
To: [email protected]
Cc: Tim Perry <[email protected]>
Sent: Mon, March 15, 2010 1:45:09 PM
Subject: Re: [Haskell-beginners] Parsec 3.0

Am Montag 15 März 2010 21:19:59 schrieb Tim Perry:
> When I install Parsec using Cabal, I get version 2.1.0.1. Is there a way
> to get version 3.1? Or do I have to build it by hand?

cabal install parsec-3.1

If you want a version other than the default, you have to give the package 
name including the version number.

>
> Thanks,
> Tim


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

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


End of Beginners Digest, Vol 21, Issue 16
*****************************************

Reply via email to