[Haskell-beginners] pattern matching on a common element
briand at aracnet.com
briand at aracnet.com
Fri Nov 25 07:08:02 UTC 2016
On Fri, 25 Nov 2016 12:06:06 +0530
Rahul Muttineni <rahulmutt at gmail.com> wrote:
> data X =
> A1 { name :: String, d :: Double}
> | A2 { name :: String, i :: Int}
> | A3 { name :: String, d1 :: Double, i1 :: Int}
>
> Now you can use `name` directly to get the string component of the
> different variants.
>
> Hope that helps!
oops, i forgot to mention.
i'd like to be able to write my code;
x = [ A1 "a1" 2.0, A2 "a2" 3 ]
etc... to save myself a lot of typing.
More information about the Beginners
mailing list