Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
possum
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Conor McBride
possum
Commits
ca41b96c
Commit
ca41b96c
authored
5 years ago
by
Conor McBride
Browse files
Options
Downloads
Patches
Plain Diff
a bit of Stuff
parent
247f9da3
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
src/.ghci
+1
-0
1 addition, 0 deletions
src/.ghci
src/Stuff/.ghci
+1
-0
1 addition, 0 deletions
src/Stuff/.ghci
src/Stuff/BwdFwd.lhs
+1
-0
1 addition, 0 deletions
src/Stuff/BwdFwd.lhs
src/Stuff/BwdFwd.md
+77
-0
77 additions, 0 deletions
src/Stuff/BwdFwd.md
with
80 additions
and
0 deletions
src/.ghci
0 → 100644
+
1
−
0
View file @
ca41b96c
:set -pgmL markdown-unlit
This diff is collapsed.
Click to expand it.
src/Stuff/.ghci
0 → 120000
+
1
−
0
View file @
ca41b96c
../.ghci
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/Stuff/BwdFwd.lhs
0 → 120000
+
1
−
0
View file @
ca41b96c
BwdFwd.md
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/Stuff/BwdFwd.md
0 → 100644
+
77
−
0
View file @
ca41b96c
Backwards and Forwards Lists
============================
I like to have types of backwards and forwards lists that are not the built in
list types.
```
haskell
{-# LANGUAGE DeriveFunctor, DeriveFoldable, DeriveTraversable #-}
module
BwdFwd
where
data
Bwd
x
=
B0
|
Bwd
x
:<
x
deriving
(
Functor
,
Foldable
,
Traversable
,
Show
,
Eq
)
infixl
5
:<
data
Fwd
x
=
F0
|
x
:>
Fwd
x
deriving
(
Functor
,
Foldable
,
Traversable
,
Show
,
Eq
)
infixr
5
:>
```
I tend to call forwards lists things like
`xs`
, while the backwards lists
get called things like
`xz`
. The
`z`
is like an
`s`
backwards, and perhaps
also suggestive of zipper constructions.
They are intended to capture spatially organised data, so they are
not
`Monad`
instances, and they are applicative in the manner of zip.
```
haskell
instance
Applicative
Bwd
where
pure
x
=
pure
x
:<
x
(
fz
:<
f
)
<*>
(
sz
:<
s
)
=
(
fz
<*>
sz
)
:<
f
s
_
<*>
_
=
B0
instance
Applicative
Fwd
where
pure
x
=
x
:>
pure
x
(
f
:>
fs
)
<*>
(
s
:>
ss
)
=
f
s
:>
(
fs
<*>
ss
)
_
<*>
_
=
F0
```
Of course, they are
`Monoid`
s.
```
haskell
instance
Monoid
(
Bwd
x
)
where
mempty
=
B0
mappend
xz
B0
=
xz
mappend
xz
(
yz
:<
y
)
=
mappend
xz
yz
:<
y
instance
Monoid
(
Fwd
x
)
where
mempty
=
F0
mappend
F0
ys
=
ys
mappend
(
x
:>
xs
)
ys
=
x
:>
mappend
xs
ys
```
You can shuffle between them.
```
haskell
(
<><
)
::
Bwd
x
->
Fwd
x
->
Bwd
x
xz
<><
F0
=
xz
xz
<><
(
x
:>
xs
)
=
(
xz
:<
x
)
<><
xs
infixl
5
<><
(
<>>
)
::
Bwd
x
->
Fwd
x
->
Fwd
x
B0
<>>
xs
=
xs
(
xz
:<
x
)
<>>
xs
=
xz
<>>
(
x
:>
xs
)
infixr
5
<>>
```
Colloquially,
`<><`
is known as
‘
fish
’
because it looks like one.
That means
`<>>`
gets called
‘
chips
’
.
### Boring superclass instances
```
haskell
instance
Semigroup
(
Bwd
x
)
where
(
<>
)
=
mappend
instance
Semigroup
(
Fwd
x
)
where
(
<>
)
=
mappend
```
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment