mirror of
https://github.com/carp-lang/Carp.git
synced 2024-10-11 20:49:05 +03:00
33 lines
745 B
Plaintext
33 lines
745 B
Plaintext
(use IO)
|
|
(use Int)
|
|
(use Array)
|
|
|
|
(defmodule ArrayExtension
|
|
(defn fmap [f a] (Array.map f a))
|
|
)
|
|
|
|
(deftype Box [x Int])
|
|
|
|
(defmodule Box
|
|
(defn fmap [f box] (let [new-x (f (Box.x &box))]
|
|
(Box.set-x box new-x))))
|
|
|
|
(use Box)
|
|
(use ArrayExtension)
|
|
|
|
;;(defn higherOrder [x] (fmap inc x))
|
|
|
|
(defn main []
|
|
(do
|
|
(println &(str (Box.x (ref (fmap inc (Box.init 100))))))
|
|
(println &(str (Box.x (ref (Box.fmap inc (Box.init 100))))))
|
|
(println &(str (ref (ArrayExtension.fmap inc [10 20 30 40 50]))))
|
|
(println &(str (ref (fmap inc [10 20 30 40 50]))))
|
|
(println &(Array.str (ref (fmap inc [10 20 30 40 50]))))
|
|
(println &(Array.str (ref (ArrayExtension.fmap inc [10 20 30 40 50]))))
|
|
))
|
|
|
|
(build)
|
|
(run)
|
|
(quit)
|