Comments (1)
@refried this was trickier than I thought. :) I got a compiling, working version after about 2 hours. Probably should have done that sooner rather than sending you on a wild goose chase. My bad. :( I hope this was still a good learning exercise.
I fiddled a bit with different representations and found it was pretty easy to express with the following:
{-# Language ScopedTypeVariables #-}
{-# Language BangPatterns #-}
{-# Language ExistentialQuantification #-}
{-# Language Rank2Types #-}
{-# Language GADTs #-}
module Stream where
import Control.Applicative
import Control.Monad
data Stream f a = forall a0 . Stream (forall b . Stack f a b -> Stack f a0 b)
data Stack f a b where
Empty :: Stack f a a
Cons :: [Segment f a] -> Stack f a b -> Stack f a b
Bind :: (a -> Stream f b) -> Stack f b c -> Stack f a c
data Segment f a where
Emit :: a -> Segment f a
Eval :: f a -> Segment f a
Append :: Stream f a -> Segment f a
data ViewL f a b where
Unbound :: [Segment f a] -> ViewL f a a
Bound :: [Segment f a] -> (a -> Stream f b) -> Stack f b c -> ViewL f a c
And some helper functions:
unbind :: Stack f a b -> ViewL f a b
bindSegment :: (x -> Stream f y) -> Segment f x -> Segment f y
From there the implementations of uncons
and run
became a lot more inevitable - you just unbind
the stack, pattern match, and handle all the cases. It might be possible to implement in terms of the simpler representation I gave earlier.
With the earlier representation, implementing everything up through MonadPlus
should still be trivial, it's just the two interpreters, uncons
and run
, that are much trickier.
If you'd still like to give this a try, start with the representation I just gave and go from there. Otherwise we can go over my 'answer' tomorrow.
from unison.
Related Issues (20)
- `ucm` wrapper breaks when called from a path with spaces in it
- history command and nondeterministic transcripts
- `merge.preview` shows hashes even if the definitions have names
- design and implementation for pack files / pull bundles HOT 1
- Possible unimplemented functions in JIT's TCP HOT 3
- switch should clear last scratch save
- `push`/`pull` don't accept `project/branch:path` args like `fork` does
- add proper `libb2` dependency to `unison-runtime` HOT 6
- chore: eliminate the use of loose code in transcripts
- remove `update.old`
- (possibly) LSP missing type names from scratch file? HOT 4
- run command: should threads be able to keep themselves running after interrupt? HOT 3
- delete.term with numbered arg fails and with a cryptic message HOT 1
- structured numbered args megaticket
- Allow `Debug.toText` builtin to be called in sandboxed code
- redesign `add`/`update`/`commit`
- migration to reset user's current path to the root of their current project
- improve error message for run.native tests.jit.only HOT 1
- new `update` doesn't really do the right thing when updating a term to a constructor
- create transcript creation guide for submitting tickets
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from unison.