September Morn Update
This commit is contained in:
parent
4e2d22a71d
commit
aac6731f2c
6856 changed files with 141342 additions and 21127 deletions
|
|
@ -1,6 +1,7 @@
|
|||
#ifndef SILLY_H
|
||||
#define SILLY_H
|
||||
#include "intefaceAbs.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
typedef struct sillyStruct *Silly;
|
||||
extern Silly NewSilly( double, const char *);
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
#include "silly.h"
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
struct sillyStruct {
|
||||
|
|
|
|||
40
Task/Abstract-type/Crystal/abstract-type.crystal
Normal file
40
Task/Abstract-type/Crystal/abstract-type.crystal
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
abstract class Animal # only abstract class can have abstract methods
|
||||
abstract def move
|
||||
abstract def think
|
||||
|
||||
# abstract class can have normal fields and methods
|
||||
def initialize(@name : String)
|
||||
end
|
||||
|
||||
def process
|
||||
think
|
||||
move
|
||||
end
|
||||
end
|
||||
|
||||
# WalkingAnimal still have to be declared abstract because `think` was not implemented
|
||||
abstract class WalkingAnimal < Animal
|
||||
def move
|
||||
puts "#{@name} walks"
|
||||
end
|
||||
end
|
||||
|
||||
class Human < WalkingAnimal
|
||||
property in_car = false
|
||||
|
||||
def move
|
||||
if in_car
|
||||
puts "#{@name} drives a car"
|
||||
else
|
||||
super
|
||||
end
|
||||
end
|
||||
|
||||
def think
|
||||
puts "#{@name} thinks"
|
||||
end
|
||||
end
|
||||
|
||||
# Animal.new # => can't instantiate abstract class
|
||||
he = Human.new("Andrew") # ok
|
||||
he.process
|
||||
26
Task/Abstract-type/Mercury/abstract-type.mercury
Normal file
26
Task/Abstract-type/Mercury/abstract-type.mercury
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
:- module eq.
|
||||
:- interface.
|
||||
|
||||
:- typeclass eq(T) where [
|
||||
pred (T::in) == (T::in) is semidet,
|
||||
pred (T::in) \= (T::in) is semidet
|
||||
].
|
||||
|
||||
:- pred f(T::in) is semidet <= eq(T).
|
||||
|
||||
:- type foo
|
||||
---> foo(
|
||||
x :: int,
|
||||
str :: string
|
||||
).
|
||||
|
||||
:- instance eq(foo).
|
||||
|
||||
:- implementation.
|
||||
|
||||
f(X) :- X == X.
|
||||
|
||||
:- instance eq(foo) where [
|
||||
A == B :- (A^x = B^x, A^str = B^str),
|
||||
A \= B :- not A == B
|
||||
].
|
||||
Loading…
Add table
Add a link
Reference in a new issue