Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
StdEnv-doc
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
Operations
Operations
Incidents
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Cloogle
StdEnv-doc
Commits
ac2aaf55
Commit
ac2aaf55
authored
Aug 22, 2018
by
John van Groningen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
move module StdMaybe from StdLib to StdEnv
parent
39d7cd70
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
93 additions
and
0 deletions
+93
-0
StdMaybe.dcl
StdMaybe.dcl
+36
-0
StdMaybe.icl
StdMaybe.icl
+57
-0
No files found.
StdMaybe.dcl
0 → 100644
View file @
ac2aaf55
definition
module
StdMaybe
// ********************************************************************************
// Clean StdLib library module, version 1.0
// ********************************************************************************
from
StdOverloaded
import
class
==(..);
::
Maybe
x
=
Just
x
|
Nothing
isJust
::
!(
Maybe
.
x
)
->
Bool
// case @1 of (Just _) -> True; _ -> False
isNothing
::
!(
Maybe
.
x
)
->
Bool
// not o isJust
fromJust
::
!(
Maybe
.
x
)
->
.
x
// \(Just x) -> x
// for possibly unique elements:
isJustU
::
!
u
:(
Maybe
.
x
)
->
(!
Bool
,
!
u
:
Maybe
.
x
)
isNothingU
::
!
u
:(
Maybe
.
x
)
->
(!
Bool
,
!
u
:
Maybe
.
x
)
mapMaybe
::
.(.
x
->
.
y
)
!(
Maybe
.
x
)
->
Maybe
.
y
// mapMaybe f (Just x) = Just (f x)
// mapMaybe f Nothing = Nothing
instance
==
(
Maybe
x
)
|
==
x
// Nothing==Nothing
// Just a ==Just b <= a==b
maybeToList
::
!(
Maybe
.
a
)
->
[.
a
];
// returns list with no or one element
listToMaybe
::
![.
a
]
->
.
Maybe
.
a
;
// returns Just head of list if possible
catMaybes
::
![
Maybe
.
a
]
->
.[.
a
];
// catMaybes ms = [ m \\ Just m <- ms ]
StdMaybe.icl
0 → 100644
View file @
ac2aaf55
implementation
module
StdMaybe
// ********************************************************************************
// Clean StdLib library module, version 1.0
// ********************************************************************************
from
StdOverloaded
import
class
==(..);
::
Maybe
x
=
Just
x
|
Nothing
isJust
::
!(
Maybe
.
x
)
->
Bool
isJust
Nothing
=
False
isJust
_
=
True
isNothing
::
!(
Maybe
.
x
)
->
Bool
isNothing
Nothing
=
True
isNothing
_
=
False
isJustU
::
!
u
:(
Maybe
.
x
)
->
(!
Bool
,
!
u
:
Maybe
.
x
)
isJustU
nothing
=:
Nothing
=
(
False
,
nothing
)
isJustU
just
=
(
True
,
just
)
isNothingU
::
!
u
:(
Maybe
.
x
)
->
(!
Bool
,
!
u
:
Maybe
.
x
)
isNothingU
nothing
=:
Nothing
=
(
True
,
nothing
)
isNothingU
just
=
(
False
,
just
)
fromJust
::
!(
Maybe
.
x
)
->
.
x
fromJust
(
Just
x
)
=
x
mapMaybe
::
.(.
x
->
.
y
)
!(
Maybe
.
x
)
->
Maybe
.
y
mapMaybe
f
(
Just
x
)
=
Just
(
f
x
)
mapMaybe
_
nothing
=
Nothing
instance
==
(
Maybe
x
)
|
==
x
where
(==)
Nothing
maybe
=
case
maybe
of
Nothing
->
True
just
->
False
(==)
(
Just
a
)
maybe
=
case
maybe
of
Just
b
->
a
==
b
nothing
->
False
maybeToList
::
!(
Maybe
.
a
)
->
[.
a
];
maybeToList
Nothing
=
[]
maybeToList
(
Just
a
)
=
[
a
]
listToMaybe
::
![.
a
]
->
.
Maybe
.
a
;
listToMaybe
[]
=
Nothing
listToMaybe
[
a
:_]
=
Just
a
catMaybes
::
![
Maybe
.
a
]
->
.[.
a
];
catMaybes
ms
=
[
m
\\
Just
m
<-
ms
]
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment