Skip to content

Instantly share code, notes, and snippets.

View abelbraaksma's full-sized avatar
🎯
Focusing

Abel Braaksma abelbraaksma

🎯
Focusing
View GitHub Profile
@gusty
gusty / polyvariadic.fsx
Last active July 20, 2023 15:19
Polyvariadic functions in F#
// Unfortunatelly it stopped working in F# 4.1 after this PR https://github.com/Microsoft/visualfsharp/pull/1650
// Will ask to revert it
type FoldArgs<'t> = FoldArgs of ('t -> 't -> 't)
let inline foldArgs f (x:'t) (y:'t) :'rest = (FoldArgs f $ Unchecked.defaultof<'rest>) x y
type FoldArgs<'t> with
static member inline ($) (FoldArgs f, _:'t-> 'rest) = fun (a:'t) -> f a >> foldArgs f
static member ($) (FoldArgs f, _:'t ) = f
@dsyme
dsyme / gist:bfed2eed788c7ba58ccc
Last active July 4, 2022 22:23
Naked type aliases can add and name constraints
// This F# language suggestion wants a way to name collections of constraints:
// http://fslang.uservoice.com/forums/245727-f-language/suggestions/8509687-add-constraints-as-a-language-construct
//
// This is a type alias X<T> = T, so X<int> = int etc.
type X<'T> = 'T
// This is a type alias X<T> = T which adds a constraint
type WithStruct<'T when 'T : struct> = 'T
@odinhaus
odinhaus / FastCopy.cs
Created November 16, 2016 16:50
Fast C# Byte[] Copier Using Cpblk IL Instruction
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace Tests
@swlaschin
swlaschin / FsCsInterop.md
Last active April 7, 2024 20:33
F# to C# interop tips

Tips on exposing F# to C#

Api and Methods

I suggest that you create one or more Api.fs files to expose F# code in a C# friendly way.

In this file:

  • Define functions with PascalCase names. They will appear to C# as static methods.
  • Functions should use tuple-style declarations (like C#) rather than F#-style params with spaces.
@rwp0
rwp0 / config.yml
Last active February 22, 2024 16:06
GH CLI Transfer Repository Ownership Alias
# ~/.config/gh/config.yml
# What protocol to use when performing git operations. Supported values: ssh, https
git_protocol: https
# What editor gh should run when creating issues, pull requests, etc. If blank, will refer to environment.
editor:
# When to interactively prompt. This is a global config that cannot be overridden by hostname. Supported values: enabled, disabled
prompt: enabled
# A pager program to send command output to, e.g. "less". Set the value to "cat" to disable the pager.
pager: