singrdk/base/Libraries/Policy/Functor.cs

43 lines
1.4 KiB
C#
Raw Permalink Normal View History

2008-11-17 18:29:00 -05:00
// ----------------------------------------------------------------------------
2008-03-05 09:52:00 -05:00
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
2008-11-17 18:29:00 -05:00
// ----------------------------------------------------------------------------
2008-03-05 09:52:00 -05:00
2008-11-17 18:29:00 -05:00
namespace Microsoft.Singularity.Policy.Engine
{
2008-03-05 09:52:00 -05:00
// A Functor contains a symbol and an arity. The
// functor f/3 is represented by new Functor("f", 3).
internal class Functor : Cell {
readonly string _name;
readonly uint _arity;
internal Functor(string name, uint arity) {
_name = name;
_arity = arity;
}
internal uint Arity { get { return _arity; } }
public static bool operator ==(Functor f0, Functor f1) {
return f0._name == f1._name && f0._arity == f1._arity;
}
public static bool operator !=(Functor f0, Functor f1) {
return !(f0 == f1);
}
public override bool Equals(object obj) {
2008-11-17 18:29:00 -05:00
if (obj == null) {
return false;
}
2008-03-05 09:52:00 -05:00
Functor that = obj as Functor;
2008-11-17 18:29:00 -05:00
if ((object)that == null) {
return false;
}
2008-03-05 09:52:00 -05:00
return this == that;
}
public override int GetHashCode() {
return _name.GetHashCode() ^ _arity.GetHashCode();
}
public override string ToString() {
return _name + "/" + _arity.ToString();
}
}
}