All Projects → unchartedworks → HaskellRed

unchartedworks / HaskellRed

Licence: MIT license
A functional library for Red programmers

Programming Languages

Red
21 projects
Rebol
56 projects

HaskellRed

A functional library for Red programmers.

Prerequisites

  • Red 0.6.3+

How to use it

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]

Examples

Data List

map

xs: [1 2 3]
map :to-string xs
["1" "2" "3"]

filter

xs: [1 "2" 3 "4" 5 "6"]
filter :integer? xs
[1 3 5]

foldl

xs: [1 2 3 4]
f: func [y x][x * y]
foldl :f 1 xs
24

Data Function

Function Composition

f1: func [x][x * 2]
f2: func [x][length? x]
f:  :f1 . :f2
f "abc"
6

Maybe

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!"

Control Monad

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.

Development

Test

./run-test

screen shot 2017-10-30 at 14 24 10

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].