ku-fpg / hermit-shell

HERMIT with GHCi shell
BSD 3-Clause "New" or "Revised" License
2 stars 0 forks source link

Revisit sendCrumb and make it composable #37

Open andygill opened 9 years ago

andygill commented 9 years ago

In one of our examples (new_reverse) we do

sendCrumb forallBody ; sendCrumb forallBody ; sendCrumb forallBody
sendCrumb consequent

We want a way of saying jump through all the forallBody, like repeat (sendCrumb forallBody)

xich commented 9 years ago

The old shell has a foralls-body for this. Though in the new shell you can probably just use the underlying KURE combinator that applies a crumb to exhaustion:

forallsBodyT = extractT (exhaustRepeatCrumbT Forall_Body)

https://github.com/ku-fpg/hermit/commit/e78bc8935b1811d60ea035ff4f06b4298d6ce4e5#diff-28551d24af9d13dacb97153e14e919ecR300

andygill commented 9 years ago

I've started a page about navigation.

https://github.com/ku-fpg/hermit-shell/wiki/Navigation

Sculthorpen commented 9 years ago

I agree with all of Drew's remarks on this topic. A few further comments:

KURE provides the synonym:

type Path crumb = [crumb]

I would suggest using that where possible (e.g. pathR) to distinguish from non-path lists of Crumbs (e.g. look).

Crumbs are distinct atomic values that uniquely identify a child node. This should not be changed. If you want a concept that is more general than this, or you want to simplify the API so that users don't have to consider both crumbs and paths, you could just expose paths, and use singleton paths in place of crumbs. I haven't looked at hermit-shell, so I'm not sure whether you want Path or LocalPath (the latter is a snoc list).

There is no such thing as an upwards (or sidewards) crumb or path. This is inherent to the design of KURE, where only the current subtree can be transformed.

In KURE, one can construct a Lens from a crumb or Path using the following:

childL :: (ReadPath c crumb, Eq crumb, MonadCatch m) => crumb -> Lens c m u u
pathL :: (ReadPath c crumb, Eq crumb, Walker c u, MonadCatch m) => Path crumb -> Lens c m u u

In practice, I think we generally found it easier to work with Paths than Lenses. E.g. it is impossible to build an upwards lens, but one can navigate a LocalPath upwards by just deleting a suffix of the path. I think HERMIT just creates the Lens from the Path immediately prior to applying a transformation.

andygill commented 9 years ago

Thanks Neil. This is useful.