Saturday, 24 August 2013

Comparing type system of Haskell with C#, looking for analogues

Comparing type system of Haskell with C#, looking for analogues

I'm pretty new a Haskell programming. I'm trying to deal with its classes,
data, instances and newtype. Here is what I've understood:
data NewData = Constr1 Int Int | Constr2 String Float
is about the same as (Java or C#):
class NewData {
private int a, b;
private string c;
private float d;
/* get'ers and set'ers for a, b, c and d
................
*/
private NewData() { }
private NewData(int a, int b) {
this.a = a;
this.b = b;
}
private NewData(string c, float d) {
this.c = c;
this.d = d;
}
public static Constr1(int a, int b) {
return new NewData(a, b);
}
public static Constr2(string c, float d) {
return new NewData(c, d);
}
}
And
class SomeClass a where
method1 :: [a] -> Bool
for
interface SomeInterface<T> {
public bool method1(List<T> someParam);
}
// or
abstract class SomeClass<T> {
public abstract bool method1(List<T> someParam);
}
And
instance SomeClass Int where
method1 a = 5 == head a -- this doesn't have any meaning, though, but
this is correct
for
class SomeClassInstance<Int>: SomeClass {
public bool method1(List<Int> param) {
return param.first == 5; // I don't remember the method's name
exactly, it doesn't matter
}
}
Are all these correct? What about newtype, how can I represent it in C# or
Java?

No comments:

Post a Comment