[m-dev.] Calling hell from heaven
Peter Ross
peter.ross at miscrit.be
Sat May 19 00:53:58 AEST 2001
Hi,
Find attached two files which show how we currently interoperate with a
class called Person defined in C#. We then use and extend that class in
mercury to implement employee.
The full example can be found in the dotnet repository in the
intgen/tests/property directory.
Note that at the .IL level there is no inheritance going on.
The next thing on the todo list is to produce a class Employee which
inherits from Person. This is necessary so that we can start writing MS
Transaction Server components in Mercury. These components need to
inherit from some object, I think the MarshallByRef object.
Pete
-------------- next part --------------
%------------------------------------------------------------------------------%
%------------------------------------------------------------------------------%
:- module use_person.
:- interface.
:- import_module io.
:- pred main(io__state::di, io__state::uo) is det.
:- implementation.
:- import_module 'mscorlib_mercury', 'mscorlib_mercury__mObject'.
:- import_module 'Person_mercury', 'Person_mercury__mPerson'.
%------------------------------------------------------------------------------%
main -->
{ p(Name, employee(new, 10), E) },
io__write_string(Name),
io__nl,
{ q(Salary, Name2, E, _) },
io__write_string(Name2),
io__nl,
io__write_int(Salary),
io__nl.
:- pred q(int::out, string::out, P::di, P::uo) is det <= ('Employee'(P)).
q(Salary, Name) -->
'Name'(Name),
'Salary'(Salary).
:- pred p(string::out, P::di, P::uo) is det <= ('Person'(P)).
p(S) -->
'Name'("Peter"),
'Name'(S).
%------------------------------------------------------------------------------%
:- typeclass 'Employee'(T) <= 'Person'(T) where [
pred 'Salary'(int, T, T),
mode 'Salary'(in, di, uo) is det,
mode 'Salary'(out, di, uo) is det
].
:- type employee
---> employee(
person :: 'Person.Person',
salary :: int
).
:- instance 'Employee'(employee) where [
pred('Salary'/3) is salary
].
:- instance 'Person'(employee) where [
pred('Name'/3) is name
].
:- instance 'Object'(employee) where [
].
:- pred salary(int, employee, employee).
:- mode salary(in, di, uo) is det.
:- mode salary(out, di, uo) is det.
:- pragma promise_pure(salary/3).
salary(S::in, employee(P, _)::di, employee(P, NewS)::uo) :-
unsafe_promise_unique(S, NewS).
salary(S::out, employee(P, S)::di, employee(P, NewS)::uo) :-
unsafe_promise_unique(S, NewS).
:- pred name(string, employee, employee).
:- mode name(in, di, uo) is det.
:- mode name(out, di, uo) is det.
name(Name, employee(P0, S), employee(P, S)) :-
'Name'(Name, P0, P).
%------------------------------------------------------------------------------%
%------------------------------------------------------------------------------%
-------------- next part --------------
namespace Person
{
using System;
/// <summary>
/// Summary description for Class1.
/// </summary>
public class Person
{
public Person()
{
//
// TODO: Add Constructor Logic here
//
}
private string name;
public string Name
{
get
{
return name;
}
set
{
name = value;
}
}
}
/*
public class Employee : Person
{
public Employee()
{
}
private int salary;
public int Salary
{
get
{
return salary;
}
set
{
salary = value;
}
}
}
*/
}
More information about the developers
mailing list