forked from HOL-Theorem-Prover/HOL
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge commit '6c54683e2ad37ea4530953b33fc5aa1c8efd5e4d' into probabil…
…ity_dev
- Loading branch information
Showing
14 changed files
with
111 additions
and
112 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
signature Listener = sig | ||
|
||
type 'a t | ||
exception DUP of string | ||
val add_listener : 'a t -> (string * ('a -> unit)) -> unit | ||
val remove_listener : 'a t -> string -> ('a -> unit) option | ||
val listeners : 'a t -> (string * ('a -> unit)) list | ||
val new_listener : unit -> 'a t | ||
val call_listener : 'a t -> 'a -> (string * ('a -> unit) * exn) list | ||
val without_one : 'a t -> string -> ('b -> 'c) -> ('b -> 'c) | ||
val without_all : 'a t -> ('b -> 'c) -> ('b -> 'c) | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
structure Listener :> Listener = | ||
struct | ||
|
||
open Unsynchronized | ||
type 'a t = (string * ('a -> unit)) list ref | ||
exception DUP of string | ||
|
||
fun new_listener () : 'a t = ref [] | ||
|
||
fun add_listener (r:'a t) (sf as (s,f)) = | ||
let | ||
val t = !r | ||
in | ||
case List.find (fn (s', _) => s' = s) t of | ||
NONE => r := sf :: t | ||
| SOME _ => raise DUP s | ||
end | ||
|
||
fun remove_listener (r:'a t) s = | ||
let | ||
val t = !r | ||
val (fopt, rest) = | ||
Portable.trypluck' (fn (s',f) => if s' = s then SOME f else NONE) t | ||
in | ||
r := rest; | ||
fopt | ||
end | ||
|
||
fun listeners (t:'a t) = (!t) | ||
|
||
fun call_listener (t:'a t) v = | ||
let | ||
fun foldthis (kf as (k,f), A) = | ||
case Exn.capture f v of | ||
Exn.Res () => A | ||
| Exn.Exn e => (k,f,e) :: A | ||
in | ||
List.foldr foldthis [] (!t) | ||
end | ||
|
||
fun without_one (r:'a t) s f x = | ||
let | ||
val t = !r | ||
val (_, t') = | ||
Portable.trypluck' (fn (s',f) => if s' = s then SOME () else NONE) t | ||
in | ||
setmp r t' f x | ||
end | ||
|
||
fun without_all r f x = setmp r [] f x | ||
|
||
end (* struct *) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters