A functional library for Red programmers.
- Red 0.6.3+
To use HaskellRed, just include haskell.red in your file. For instance,
#include %haskell.red
print isControl #"t"
print map :to-string [1 2 3]
xs: [1 2 3]
map :to-string xs
["1" "2" "3"]
xs: [1 "2" 3 "4" 5 "6"]
filter :integer? xs
[1 3 5]
xs: [1 2 3 4]
f: func [y x][x * y]
foldl :f 1 xs
24
f1: func [x][x * 2]
f2: func [x][length? x]
f: :f1 . :f2
f "abc"
6
hit: [x] -> [Just (x + 8)]
stand: [x] -> [either x > 21 [Nothing][Just x]]
win: [x] -> [Just "$1000"]
showtime: [x] -> [Just ("You win " ++ x ++ "!")]
blackjack: [x [object!]] -> [x >>= :hit >>= :hit >>= :stand >>= :win >>= :showtime]
blackjack Just 3
Just "You win $1000!"
Red [
Title: "all test script"
Author: "unchartedworks"
File: %all-test.red
Tabs: 4
Rights: "unchartedworks. All rights reserved."
License: "MIT"
]
#include %haskell.red
isTestFile: [x] -> [(isSuffixOf "-test.red" (to-string x)) && (%all-test.red <> x) && (not (isPrefixOf ".#" (to-string x)))]
filterTestFiles: [xs] -> [filter :isTestFile xs]
includeFile: [x] -> [#include x]
includeFiles: [xs] -> [map :includeFile xs]
%./ >>>= [read filterTestFiles includeFiles]
For more documentation, please refer to Haskell documentation and the test cases of HaskellRed.
./run-test