Skip to content

Commit

Permalink
Redefine Failure pattern to accommodate more exceptions
Browse files Browse the repository at this point in the history
Resolve wrong references in NHol.Tests project
  • Loading branch information
dungpa committed Jun 26, 2013
1 parent 4d8af8b commit ee547d0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
3 changes: 2 additions & 1 deletion NHol.Tests/NHol.Tests.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@
<HintPath>..\packages\ExtCore.0.8.29\lib\net40\ExtCore.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="FsCheck, Version=0.8.3.0, Culture=neutral, PublicKeyToken=null">
<Reference Include="FsCheck">
<HintPath>..\packages\FsCheck.0.8.3.0\lib\net40-Client\FsCheck.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="FsUnit.NUnit">
Expand Down
14 changes: 11 additions & 3 deletions NHol/lib.fs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,16 @@ let (==) (x : 'T) (y : 'T) = obj.ReferenceEquals(x, y)

let fail() = raise <| exn ()

// The exception fired by failwith is used as a control flow.
// KeyNotFoundException is not recognized in many cases, so we have to use redefine Failure for compatibility.
// Using exception as a control flow should be eliminated in the future.
let (|Failure|_|) (exn: exn) =
match exn with
| :? System.Collections.Generic.KeyNotFoundException as p -> Some p.Message
| :? System.ArgumentException as p -> Some p.Message
| Failure s -> Some s
| _ -> None

(* ------------------------------------------------------------------------- *)
(* Combinators. *)
(* ------------------------------------------------------------------------- *)
Expand All @@ -51,9 +61,6 @@ let K x y = x
let C f x y = f y x
let W f x = f x x

// NOTE : Replaced all uses of (o) with (<<) since F# does not allow (o) to be used as an infix operator.
let (o) = fun f g x -> f(g x)

let (.>>.) = fun f g (x, y) -> (f x, g y)

(* ------------------------------------------------------------------------- *)
Expand Down Expand Up @@ -453,6 +460,7 @@ let rec shareout pat all =
(* ------------------------------------------------------------------------- *)
(* Iterating functions over lists. *)
(* ------------------------------------------------------------------------- *)

// OPTIMIZE : Make this an alias for List.iter.
let rec do_list f l =
match l with
Expand Down

0 comments on commit ee547d0

Please sign in to comment.