Just another update
This commit is contained in:
parent
a25938f123
commit
00a190b0a6
6591 changed files with 94363 additions and 23227 deletions
26
Task/Abstract-type/Mathematica/abstract-type.math
Normal file
26
Task/Abstract-type/Mathematica/abstract-type.math
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
(* Define an interface, Foo, which requires that the functions Foo, Bar, and Baz be defined *)
|
||||
InterfaceFooQ[obj_] := ValueQ[Foo[obj]] && ValueQ[Bar[obj]] && ValueQ[Baz[obj]];
|
||||
PrintFoo[obj_] := Print["Object ", obj, " does not implement interface Foo."];
|
||||
PrintFoo[obj_?InterfaceFooQ] := Print[
|
||||
"Foo: ", Foo[obj], "\n",
|
||||
"Bar: ", Bar[obj], "\n",
|
||||
"Baz: ", Baz[obj], "\n"];
|
||||
|
||||
(* Extend all integers with Interface Foo *)
|
||||
Foo[x_Integer] := Mod[x, 2];
|
||||
Bar[x_Integer] := Mod[x, 3];
|
||||
Baz[x_Integer] := Mod[x, 5];
|
||||
|
||||
(* Extend a particular string with Interface Foo *)
|
||||
Foo["Qux"] = "foo";
|
||||
Bar["Qux"] = "bar";
|
||||
Baz["Qux"] = "baz";
|
||||
|
||||
(* Print a non-interface object *)
|
||||
PrintFoo[{"Some", "List"}];
|
||||
(* And for an integer *)
|
||||
PrintFoo[8];
|
||||
(* And for the specific string *)
|
||||
PrintFoo["Qux"];
|
||||
(* And finally a non-specific string *)
|
||||
PrintFoo["foobarbaz"]
|
||||
7
Task/Abstract-type/Oberon-2/abstract-type.oberon-2
Normal file
7
Task/Abstract-type/Oberon-2/abstract-type.oberon-2
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
TYPE
|
||||
Animal = POINTER TO AnimalDesc;
|
||||
AnimalDec = RECORD [ABSTRACT] END;
|
||||
|
||||
(* Cat inherits from Animal *)
|
||||
Cat = POINTER TO CatDesc;
|
||||
CatDesc = RECORD (AnimalDesc) END;
|
||||
5
Task/Abstract-type/Seed7/abstract-type.seed7
Normal file
5
Task/Abstract-type/Seed7/abstract-type.seed7
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
const type: myInterf is sub object interface;
|
||||
|
||||
const func integer: method1 (in myInterf: interf, in float: aFloat) is DYNAMIC;
|
||||
const func integer: method2 (in myInterf: interf, in string: name) is DYNAMIC;
|
||||
const func integer: add (in myInterf: interf, in integer: a, in integer: b) is DYNAMIC;
|
||||
6
Task/Abstract-type/Standard-ML/abstract-type-1.ml
Normal file
6
Task/Abstract-type/Standard-ML/abstract-type-1.ml
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
signature QUEUE = sig
|
||||
type 'a queue
|
||||
val empty : 'a queue
|
||||
val enqueue : 'a -> 'a queue -> 'a queue
|
||||
val dequeue : 'a queue -> ('a * 'a queue) option
|
||||
end
|
||||
6
Task/Abstract-type/Standard-ML/abstract-type-2.ml
Normal file
6
Task/Abstract-type/Standard-ML/abstract-type-2.ml
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
signature LIST_QUEUE = sig
|
||||
type 'a queue = 'a list
|
||||
val empty : 'a queue
|
||||
val enqueue : 'a -> 'a queue -> 'a queue
|
||||
val dequeue : 'a queue -> ('a * 'a queue) option
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue