[Haskell-cafe] Constraints at construction

Henning Thielemann lemming at henning-thielemann.de
Sun Oct 12 16:28:45 EDT 2008


On Thu, 9 Oct 2008, Iain Barnett wrote:

> If I were to create an object in C#, for instance, I could add code to the 
> constructor that might limit the type further e.g.
>
>
> public class Car
> {
> 	string model;
> 	int wheels;
>
> 	public Car ( string model, int no_of_wheels )
> 	{
> 		if (  no_of_wheels <= 2 ) {
> 			throw new Exception( "a car must have at least 3 
> wheels");
> 		}
> 				this.model = model;
> 		this.no_of_wheels = no_of_wheels;
> 	}
> }

I think it is not the right way to handle the number of wheels with an 
exception. This should be considered an error.
    http://www.haskell.org/haskellwiki/Error


More information about the Haskell-Cafe mailing list