Skip to content

Commit cfe7079

Browse files
authored
Merge pull request #3 from dawedawe/h_wo_q
h on raw expressions
2 parents 1447b5d + 4791e90 commit cfe7079

File tree

4 files changed

+34
-48
lines changed

4 files changed

+34
-48
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## [1.0.0] - 2024-01-20
4+
5+
### Changed
6+
7+
* Made `h expr` just work without the need for quotation wrapping.
8+
39
## [0.2.0] - 2024-01-16
410

511
### Fixed

README.md

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Fsih
22
====
33

4-
Fsih provides you with the `h` and `H.H` functions, meant to be used in the F# REPL [fsi](https://learn.microsoft.com/en-us/dotnet/fsharp/tools/fsharp-interactive/).
4+
Fsih provides you with the `h` function, meant to be used in the F# REPL [fsi](https://learn.microsoft.com/en-us/dotnet/fsharp/tools/fsharp-interactive/).
55
It's modeled after the `h` function in the Elixir [iex](https://hexdocs.pm/iex/1.16.0/IEx.html) REPL.
66

77
To use it, just start an fsi session with `dotnet fsi`.
@@ -11,9 +11,9 @@ Load the package and open the namespace:
1111
open Fsih;;
1212
```
1313

14-
Apply h to any expression wrapped in an FSharp [quotation](https://learn.microsoft.com/en-us/dotnet/fsharp/language-reference/code-quotations) to get its documentation:
14+
Apply h to any expression to get its documentation:
1515
```fsharp
16-
h <@ fst @>;;
16+
h fst;;
1717
```
1818

1919
```
@@ -31,24 +31,3 @@ fst ("first", 2) // Evaluates to "first"
3131
Full name: Microsoft.FSharp.Core.Operators.fst
3232
Assembly: FSharp.Core.dll
3333
```
34-
35-
Or apply H.H to any expression directly to get its documentation:
36-
```fsharp
37-
H.H fst;;
38-
```
39-
40-
```
41-
Description:
42-
Return the first element of a tuple, fst (a,b) = a.
43-
44-
Parameters:
45-
- tuple: The input tuple.
46-
Returns:
47-
The first value.
48-
49-
Examples:
50-
fst ("first", 2) // Evaluates to "first"
51-
52-
Full name: Microsoft.FSharp.Core.Operators.fst
53-
Assembly: FSharp.Core.dll
54-
```

src/Fsih.Tests/Tests.fs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,15 @@ let expressions =
3636
[<Theory>]
3737
[<MemberData(nameof (expressions))>]
3838
let ``fetching and parsing docs works for expressions`` ((expr, fullName): (Expr * string)) =
39-
let doc = tryGetDocumentation expr
39+
let doc = Quoted.tryGetDocumentation expr
4040

4141
match doc with
4242
| None -> Assert.False(true, sprintf "no docs for %s" fullName)
4343
| Some d -> Assert.Equal(fullName, d.FullName)
4444

4545
[<Fact>]
4646
let ``full info is as expected for Seq.splitInto`` () =
47-
let doc = tryGetDocumentation <@ Seq.splitInto @>
47+
let doc = Quoted.tryGetDocumentation <@ Seq.splitInto @>
4848

4949
match doc with
5050
| Some { Summary = summary
@@ -88,7 +88,7 @@ let ``full info is as expected for Seq.splitInto`` () =
8888

8989
[<Fact>]
9090
let ``returns is as expected for HashIdentity.FromFunctions`` () =
91-
let doc = tryGetDocumentation <@ HashIdentity.FromFunctions @>
91+
let doc = Quoted.tryGetDocumentation <@ HashIdentity.FromFunctions @>
9292

9393
match doc with
9494
| Some { Returns = Some returns } ->
@@ -101,7 +101,7 @@ let ``returns is as expected for HashIdentity.FromFunctions`` () =
101101

102102
[<Fact>]
103103
let ``remarks is as expected for List.reduce`` () =
104-
let doc = tryGetDocumentation <@ List.reduce @>
104+
let doc = Quoted.tryGetDocumentation <@ List.reduce @>
105105

106106
match doc with
107107
| Some { Remarks = Some remarks } -> Assert.Equal("Raises System.ArgumentException if list is empty", remarks)
@@ -110,7 +110,7 @@ let ``remarks is as expected for List.reduce`` () =
110110

111111
[<Fact>]
112112
let ``summary is as expected for Array.sortDescending`` () =
113-
let doc = tryGetDocumentation <@ Array.sortDescending @>
113+
let doc = Quoted.tryGetDocumentation <@ Array.sortDescending @>
114114

115115
match doc with
116116
| Some { Summary = summary } ->
@@ -122,8 +122,8 @@ let ``summary is as expected for Array.sortDescending`` () =
122122

123123
[<Fact>]
124124
let ``ReflectedDefinition works as expected`` () =
125-
let docReflected = H.TryGetDocumentation(id)
126-
let docQuoted = tryGetDocumentation <@ id @>
125+
let docReflected = TryGetDocumentation(id)
126+
let docQuoted = Quoted.tryGetDocumentation <@ id @>
127127

128128
match docReflected, docQuoted with
129129
| Some r, Some q -> Assert.True((r = q))

src/Fsih/Program.fs

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -75,28 +75,29 @@ module Logic =
7575
open Expr
7676
open Parser
7777

78-
let tryGetDocumentation expr =
79-
match exprNames expr with
80-
| Some(xmlPath, assembly, modName, implName, sourceName) ->
81-
helpText xmlPath assembly modName implName sourceName
82-
| _ -> None
83-
84-
let h (expr: Quotations.Expr) =
85-
match tryGetDocumentation expr with
86-
| None -> printfn "unable to get documentation"
87-
| Some d -> d.Print()
88-
78+
module Quoted =
79+
let tryGetDocumentation expr =
80+
match exprNames expr with
81+
| Some(xmlPath, assembly, modName, implName, sourceName) ->
82+
helpText xmlPath assembly modName implName sourceName
83+
| _ -> None
84+
85+
let h (expr: Quotations.Expr) =
86+
match tryGetDocumentation expr with
87+
| None -> printfn "unable to get documentation"
88+
| Some d -> d.Print()
89+
90+
[<AutoOpen>]
8991
type H() =
90-
static member H([<ReflectedDefinition>] expr: Quotations.Expr<_>) = h expr
91-
static member TryGetDocumentation([<ReflectedDefinition>] expr: Quotations.Expr<_>) = tryGetDocumentation expr
92+
static member h([<ReflectedDefinition>] expr: Quotations.Expr<_>) = Quoted.h expr
93+
94+
static member TryGetDocumentation([<ReflectedDefinition>] expr: Quotations.Expr<_>) =
95+
Quoted.tryGetDocumentation expr
9296

9397
module Program =
9498

9599
[<EntryPoint>]
96100
let main _argv =
97-
// h <@ id @>
98-
// H.H id
99-
h <@ List.map @>
100-
H.H List.map
101+
h id
101102

102103
0

0 commit comments

Comments
 (0)