Skip to content

Instantly share code, notes, and snippets.

View cartermp's full-sized avatar
🦫
reject modernity, become a beaver

Phillip Carter cartermp

🦫
reject modernity, become a beaver
View GitHub Profile
// Learn more about F# at http://docs.microsoft.com/dotnet/fsharp

open BenchmarkDotNet.Attributes
open BenchmarkDotNet.Running

module DotProduct =
    let rec dotProduct (vector1 : float []) (vector2 : float []) : float =

        if vector1 |> Array.length = 0 then

Title:

F# is awesome - learn what's new and what you can use it for!

Abstract:

F# is a functional cousin to the C# language. It's part of .NET, but has a lightweight syntax and several awesome features that make it a great choice for writing succinct code, web apps, and doing data scripting and analytics. It's got great tooling support, and highly active community, great package and ecosystem support, and it's used in all kinds of domains.

F# 6 is the latest release of F#, bringing some great new features that simplify some things for beginners and make it an even more well-rounded language for folks who love type safety and robustness but don't want to write a bunch of code to get those things.

// Learn more about F# at http://docs.microsoft.com/dotnet/fsharp
open BenchmarkDotNet.Attributes
open BenchmarkDotNet.Running
let MAGIC = 7
let simple n =
n &&& 0xFF
https://github.com/honeycombio/zipkin-python-opentracing
https://github.com/honeycombio/dynsampler-js
https://github.com/honeycombio/chef-honeytail
https://github.com/honeycombio/leakybucket
https://github.com/honeycombio/influx2hny
https://github.com/honeycombio/prom2hny
https://github.com/honeycombio/opentelemetry-exporter-go
https://github.com/honeycombio/opentelemetry-exporter-python
https://github.com/honeycombio/opentelemetry-dotnet
https://github.com/honeycombio/zipkin-python-opentracing
open System.Threading.Tasks
open System.Text.RegularExpressions
let regex s = Regex(s, RegexOptions.Compiled)
let input = System.IO.File.ReadAllText($"{__SOURCE_DIRECTORY__}/regexredux-input5000000.txt")
let text = (regex ">.*\n|\n").Replace(input, "")
let regexCount pattern text =
let rec loop c (m:Match) =
// Notes:
// 0. Immediately thrown off by `{` and `}` being colorized as the string literal
// 1. Bad expression diagnostic in the interpolation is correct
// 2. String literal in non-triple-quoted string diagnostic is good
// 3. Typing these out works well, editor doesn't freak out
// 4. symbol-based operations all work (symbol highlight, find refs, go to def) for symbols in interpolated stuff
// 5. Breakpoint can be set in the interp string on a single line
// 6. Using interp string with %d/%s/etc. specifiers adjusts the argument's type as expected (e.g., %d{whom} infers a valid type for 'whom')
// 7. Error recoviery for splitting the interpolated expression into a new line matches other rules for splitting things out into new lines
// 8. Quick fix to rename misspelled identifier in interpolation works
public class SomeClassInMyCode
{
public void SomeMethodIHave()
{
HelloWorldGenerated.HelloWorld.SayHello(); // calls Console.WriteLine("Hello World!") and then prints out syntax trees
}
}
<!-- This goes in the top-level property group -->
<PropertyGroup>
<LangVersion>preview</LangVersion>
</PropertyGroup>
<!-- Add this as a new ItemGroup, replacing paths and names appropriately -->
<ItemGroup>
<!-- Note that this is not a "normal" ProjectReference.
It needs the additional 'OutputItemType' and 'ReferenceOutputAssmbly' attributes. -->
<ProjectReference Include="path-to-sourcegenerator-project.csproj"
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Text;
namespace SourceGeneratorSamples
{
[Generator]
public class HelloWorldGenerator : ISourceGenerator
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Text;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Xml;
namespace MyGenerator