Skip to content

Instantly share code, notes, and snippets.

@yukitos
Last active June 11, 2016 14:42
Show Gist options
  • Save yukitos/d048370f4fda36e96357552f0cc02c63 to your computer and use it in GitHub Desktop.
Save yukitos/d048370f4fda36e96357552f0cc02c63 to your computer and use it in GitHub Desktop.

FSDN: F# API Search Engine Web Application

FSDN is a web application that uses F# API Search library. F# API Search library supports the standard signature of F# with some extentions as its criteria. This document describes the F# API Search library specific formats.

Query format specifications

Supported API signatures

API signature Query example
Functions and values in modules int -> string
Fields of records and structs Ref<'a> => 'a
Methods and properties 'a list => int
Constructors string -> Uri
Names (function and method names) head : 'a list -> 'a
Active patterns (||) : ... -> Expr -> ?

Search by name

A criteria of search by name is formatted as name : signature. If you don't want to specify the signature explicitly, use _, instead.

The following query:

id : 'a -> 'a

shows the following result:

Microsoft.FSharp.Core.Operators.id: 'T -> 'T 

And the following query:

choose : _

shows the followings:

Microsoft.FSharp.Collections.Array.choose: ('T -> option<'U>) -> 'T[] -> 'U[] 
Microsoft.FSharp.Collections.ArrayModule.Parallel.choose: ('T -> option<'U>) -> 'T[] -> 'U[] 
Microsoft.FSharp.Collections.List.choose: ('T -> option<'U>) -> list<'T> -> list<'U> 
Microsoft.FSharp.Collections.Seq.choose: ('T -> option<'U>) -> seq<'T> -> seq<'U> 
Microsoft.FSharp.Control.Event.choose: ('T -> option<'U>) -> IEvent<'Del, 'T> -> IEvent<'U> 
when 'Del : delegate and 'Del :> Delegate
Microsoft.FSharp.Control.Observable.choose: ('T -> option<'U>) -> IObservable<'T> -> IObservable<'U> 

Wildcard

By default, FSDN doesn't return results that match type parameters, such as 'a, with concrete type names, such as int. To find them, use wildcard: ?.

? -> list<?> -> ?

This query shows the following results:

Microsoft.FSharp.Collections.List.append: list<'T> -> list<'T> -> list<'T> 
Microsoft.FSharp.Collections.List.averageBy: ('T -> 'U) -> list<'T> -> 'U 
when 'U : (static member op_Addition : 'U * 'U -> 'U) and 'U : (static member DivideByInt : 'U * int -> 'U) and 'U : (static member get_Zero : unit -> 'U)
Microsoft.FSharp.Collections.List.choose: ('T -> option<'U>) -> list<'T> -> list<'U> 
Microsoft.FSharp.Collections.List.chunkBySize: int -> list<'T> -> list<list<'T>> 
Microsoft.FSharp.Collections.List.collect: ('T -> list<'U>) -> list<'T> -> list<'U> 
Microsoft.FSharp.Collections.List.contains: 'T -> list<'T> -> bool 
when 'T : equality
Microsoft.FSharp.Collections.List.countBy: ('T -> 'Key) -> list<'T> -> list<'Key * int> 
when 'Key : equality
Microsoft.FSharp.Collections.List.distinctBy: ('T -> 'Key) -> list<'T> -> list<'T> 
when 'Key : equality
(snip)

If you want to specify the same type in several places, use "named wildcard". For instance, when the following query

? -> ?

matches the following signatures:

'a -> 'a
int -> int
'a -> int
int -> string

and if you specify named wildcard as follows:

?a -> ?a

this doesn't match either 'a -> int or int -> string.

Search members

Instance members

A criteria of search instance members is formatted as receiver => signature.

To find methods that accept one argument, use receiver => arg -> returnType format.

To find methods that accept multiple arguments, use receiver => arg1 -> arg2 -> returnType or receiver => arg1 * arg2 -> returnType. By default, tuple style method arguments (arg1 * arg2) and curried style (arg1 -> arg2) are treated as identical. If you want to distinguish between them, uncheck ignore-argstyle option.

To find properties, use receiver => propertyType. To find indexed properties, use receiver => index -> propertyType.

For instance members, the specified query matches the following special cases:

  1. it matches arg -> receiver -> returnType.
  2. a query to search parameterless members (receiver => propertyType) also matches instance methods which signature is receiver => unit -> propertyType.

The following query:

string => int

illustrates an example of these special rules. This query matches the following methods and functions:

System.String.Length: int 
Microsoft.FSharp.Core.String.length: string -> int 
System.String.GetHashCode: unit -> int 

The first result System.String.Length matches exactly. In addition, Microsoft.FSharp.Core.String.length and System.String.GetHashCode are also retuned because the 1st and 2nd special rules are applied respectively.

Static members

Static members can be found by using the same query for functions and values in modules. As the same with instance methods, both arg1 -> arg2 -> returnType and arg1 * arg2 -> returnType can be used to find static methods that accepts multiple arguments.

Active patterns

A criteria of search active patterns is formatted as (||) : (args ->) inputType -> returnType.

To find partial active patterns, use (|_|) : (args ->) inputType -> returnType format.

inputType indicates a type handled by an active pattern. For instance, to find active patterns for Expr, use (||) : ... -> Expr -> ?.

args indicates parameters of an active pattern. To find active patterns that accepts multiple arguments, use (||) : arg1 -> arg2 -> inputType -> returnType. To find active patterns that accepts no arguments, use (||) : inputType -> returnType. To find active patterns that accepts zero or more arguments, use ... keyword as args: (||) : ... -> inputType -> returnType.

returnType indicates a return type of an active pattern. This must be different between active patterns each of which supports one case, multiple cases, and is partial active pattern, and option<_> or Choice<_,...,_> must be specified. Usually a wildcard (?) is recommended for returnType.

Search Options

strict option

When this option is enabled and when performing wildcard search, each of the wildcards are distinguished by its name. For instance, ?a -> ?a matches int -> int, but ?a -> ?b doesn't match int -> int. If this option is disabled, ?a -> ?b matches int -> int.

similarity option

When this option is enabled, type parameters match concrete type names, and vice-versa. The results will be ordered by its similarity. In addition, type constraint will be considered significant.

ignore-argstyle option

When this option is enabled, the difference between curried style parameter signature (arg1 -> arg2 -> returnType) and tuple style (arg1 * arg2 -> returnType) are ignored. These styles are considered as identical.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment