Skip to content

Commit

Permalink
Merge pull request #35 from mattpolzin/fix-totality
Browse files Browse the repository at this point in the history
fix totality of hasWindowWithin
  • Loading branch information
mattpolzin authored Jun 4, 2023
2 parents 5878735 + 0bda4ed commit e4faae7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/Control/NCurses.idr
Original file line number Diff line number Diff line change
Expand Up @@ -176,17 +176,23 @@ inWindow = InWindow
-- ^ NOTE: This _should_ be possible to do provably without creating a new @InWindow@ constructor just by
-- using @SetWindow@ twice but I have yet to get the proofs to work.

public export
hasWindowWithin' : InWindow w s -> HasWindow w s
hasWindowWithin' {s = (Active _ _ ((MkWindow name _ _) ** Here) _)} IsCurrentWindow = ItHasWindow
hasWindowWithin' {s = (Active i (y :: xs) ((MkWindow name k d) ** (There x)) c)} p@(IsCurrentWindow) =
let c' : InWindow name (Active i xs ((MkWindow name k d) ** x) c) = IsCurrentWindow
in moreWindowsHasWindow @{hasWindowWithin' (assert_smaller p c')}

public export
%hint
hasWindowWithin : InWindow w s => HasWindow w s
hasWindowWithin {s = (Active _ _ ((MkWindow name _ _) ** Here) _)} @{IsCurrentWindow} = ItHasWindow
hasWindowWithin {s = (Active _ _ ((MkWindow name _ _) ** (There x)) _)} @{IsCurrentWindow} = hasWindowWithin
hasWindowWithin @{p} = hasWindowWithin' p

public export
%hint
identifiesCurrentWindow : InWindow w (Active _ ws _ _) => IdentifiesWindow w ws
identifiesCurrentWindow {ws} @{p} with (hasWindowWithin @{p})
identifiesCurrentWindow {ws} @{p} | (ItHasWindow @{ident}) = ident
identifiesCurrentWindow @{p} with (hasWindowWithin @{p})
identifiesCurrentWindow @{p} | (ItHasWindow @{ident}) = ident

||| If a given state has a window, setting a new current window on that state does not
||| change the fact that the state has the original window.
Expand Down
6 changes: 6 additions & 0 deletions src/Control/NCurses/State.idr
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,12 @@ namespace Window
data HasWindow : (0 name : String) -> CursesState -> Type where
ItHasWindow : IdentifiesWindow name ws => HasWindow name (Active _ ws _ _)

public export
moreWindowsHasWindow : HasWindow name (Active i xs (MkWindow name k d ** x) c) =>
HasWindow name (Active i (y :: xs) (MkWindow name k d ** There x) c)
moreWindowsHasWindow {xs = (MkWindow name _ _ :: windows)} @{ItHasWindow @{Here}} = ItHasWindow
moreWindowsHasWindow {xs = (w :: windows)} @{ItHasWindow @{(There z)}} = ItHasWindow

public export %inline
DefaultWindow : String
DefaultWindow = "default"
Expand Down

0 comments on commit e4faae7

Please sign in to comment.