[Haskell-cafe] Something that kind of resembles OO

2010-07-09 Thread Michael Mossey
I notice in algebraic data defined with named fields, you can use the 
same name inside different constructors and then apply it to any data of 
that type.


data Vehicle = Car { ident :: String, wheel :: Circle }
 | Plane { ident :: String, stick :: Line }

f :: [Vehicle] - [String]
f = map ident

This is a little like fields in a base class.

I also see that a wrong use of accessor functions will compile but give 
a runtime error:


test = wheel (Plane foo (Line 1))

Will give a runtime error.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Something that kind of resembles OO

2010-07-09 Thread Ivan Lazar Miljenovic
Michael Mossey m...@alumni.caltech.edu writes:

 I notice in algebraic data defined with named fields, you can use the
 same name inside different constructors and then apply it to any data
 of that type.

 data Vehicle = Car { ident :: String, wheel :: Circle }
  | Plane { ident :: String, stick :: Line }

 f :: [Vehicle] - [String]
 f = map ident

 This is a little like fields in a base class.

 I also see that a wrong use of accessor functions will compile but
 give a runtime error:

 test = wheel (Plane foo (Line 1))

Well, it type-checks...

-- 
Ivan Lazar Miljenovic
ivan.miljeno...@gmail.com
IvanMiljenovic.wordpress.com
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe