Skip to content

Programming language | Types

Alexander Verbitsky edited this page Jun 4, 2019 · 11 revisions

Types

type Point(x, y);
type Rectangle(x, y, w, h):
    x1 = x
    y1 = y
    x2 = x + w
    y2 = y + h
type Circle2x{T}(x:T, y:T, r:T):
    r = r * 2

    def area() -> T:
        3.1415 * r * r
type Functor{a,b}:

    # def fmap :: (a -> b) -> f a -> f b
    def fmap(fn: (a -> b), arg: a) -> b: pass

#fmap _ Nothing       = Nothing
# fmap f (Just a)      = Just (f a)

type Maybe{T}(Functor):
    v :: {T|Nothing}

    def fmap(f: (a->b)): pass
Clone this wiki locally