From 45b44a6423c29de73de77b39e1d7c6e309962844 Mon Sep 17 00:00:00 2001 From: Camil Staps Date: Wed, 27 Jan 2016 19:04:27 +0100 Subject: [PATCH] Added Maybe-related functions; restricted imports from .dcl --- ReadLine.dcl | 7 ++++++- ReadLine.icl | 12 ++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/ReadLine.dcl b/ReadLine.dcl index 734ca20..7828e88 100644 --- a/ReadLine.dcl +++ b/ReadLine.dcl @@ -1,6 +1,6 @@ definition module ReadLine -import StdEnv +import StdClass :: Maybe a = Nothing | Just a :: HistoryItem = {line :: String, timestamp :: String} @@ -9,6 +9,11 @@ import StdEnv instance toString HistoryItem instance toString HistoryState +//Maybe functions +isNothing :: !(Maybe .x) -> Bool +isJust :: !(Maybe .x) -> Bool +fromJust :: !(Maybe .x) -> .x + //Non-library functions setReadLineName :: !String !*env -> *env diff --git a/ReadLine.icl b/ReadLine.icl index 790db28..4faf3ba 100644 --- a/ReadLine.icl +++ b/ReadLine.icl @@ -4,6 +4,18 @@ import StdEnv import code from "readLine.o" +//Maybe +isNothing :: !(Maybe .x) -> Bool +isNothing Nothing = True +isNothing _ = False + +isJust :: !(Maybe .x) -> Bool +isJust Nothing = False +isJust _ = True + +fromJust :: !(Maybe .x) -> .x +fromJust (Just x) = x + instance toString HistoryItem where toString {line,timestamp} = line +++ " (" +++ timestamp +++ ")" instance toString HistoryState where -- 2.20.1