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
#lang racket | |
(define (make-deque) (mcons null null)) | |
(define (front deque) (mcar deque)) | |
(define (rear deque) (mcdr deque)) | |
(define (set-front! deque item) (set-mcar! deque item)) | |
(define (set-rear! deque item) (set-mcdr! deque item)) | |
(define (empty? deque) (null? (front deque))) |
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
open System.Runtime.InteropServices | |
type C1() = static member M([<Out>] arg: byref<C1>) = arg <- C1(); true // byref<C1> -> bool | |
type C2() = static member M(arg: byref<C2>) = arg <- C2(); true // byref<C2> -> bool | |
type C3() = static member M(arg: outref<C3>) = arg <- C3(); true // outref<C3> -> bool | |
C1.M // val it : unit -> bool * C1 | |
C2.M // val it : C2 ref -> bool | |
C3.M // val it : unit -> bool * C2 |
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
//fsharplint:disable | |
type M<'a> = 'a option | |
let inline unit (x: 'a) : M<'a> = Some x | |
let inline (>>=) (x: M<'a>) (f: 'a -> M<'b>) : M<'b> = | |
x |> Option.bind f | |
type MonadBuilder() = | |
member _.Bind(mx: M<'a>, f: 'a -> M<'b>) = mx >>= f | |
member _.Return(x: 'a) = unit x | |
member _.ReturnFrom(mx : M<'a>) = mx |
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
open FSharp.Quotations | |
open FSharp.Linq.RuntimeHelpers | |
open System.Linq | |
open System | |
type AST = | |
| StartsWith of string | |
| Contains of string | |
| EndsWith of string |
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
let traverse (exprs: Expr<'a> list) = | |
let folder elem state = <@ %elem :: %state @> | |
let init = <@ [] @> | |
List.foldBack folder exprs init | |
[1..3] |> List.map (fun x -> <@ x @>) |> traverse |
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
open System | |
open System.Runtime.CompilerServices | |
[<Extension>] | |
type X = | |
[<Extension>] | |
static member Bind(_: OptionBuilder, v: 'a, f: 'a -> 'b option) = | |
match box v with | |
| null -> None | |
| :? string as v when String.IsNullOrEmpty v -> None |
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
type Tuple = Tuple with | |
static member inline TupleMap (Tuple, (a, b)) = fun f -> (f a, f b) | |
static member inline TupleMap (Tuple, (a, b, c)) = fun f -> (f a, f b, f c) | |
static member inline TupleMap (Tuple, (a, b, c, d)) = fun f -> (f a, f b, f c, f d) | |
let inline mapTuple f x = | |
let inline map (a: ^a) (b : ^b) = ((^a or ^b) : (static member TupleMap : ^a * ^b -> ^t) (a, b)) | |
map Tuple x f | |
mapTuple (fun x -> x * x + 1) (1, 2) |
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
namespace Data.Model.Entities | |
{ | |
using System; | |
using System.Data.Entity.Core.Metadata.Edm; | |
using System.Data.Entity.Infrastructure; | |
using System.Data.Entity.ModelConfiguration.Conventions; | |
using System.Linq; | |
using System.Reflection; | |
public class CommentSplittingFixer : IStoreModelConvention<EdmModel> |
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
using System.Diagnostics.CodeAnalysis; | |
using System; | |
static Result<Foo, Err> GetResult(bool isErr) | |
=> isErr ? Result.Ok(new Foo()) : Result.Error(new Err()); | |
Console.WriteLine(GetResult(true) switch | |
{ | |
{ Success: true, Value: var value } => value, | |
{ Success: false, Error: var error } => error, |
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
### Nullable Reference Types | |
https://devblogs.microsoft.com/dotnet/nullable-reference-types-in-csharp/ | |
https://learn.microsoft.com/en-us/ef/core/miscellaneous/nullable-reference-types#non-nullable-properties-and-initialization | |
The purpose of nullable warnings is to minimize the chance that your application throws a `System.NullReferenceException` when run. | |
To enable Nullable Reference Types for all code in a project, you can add the following to its `.csproj` file: |
OlderNewer