Skip to content

Instantly share code, notes, and snippets.

let tuple = "a","b"
let v1 = System.String.Compare(tuple) // error
let v2 = System.Object.Equals(tuple) // no error
@isaacabraham
isaacabraham / gist:3314300b3758cfca23df30e8dc3ca814
Last active December 23, 2024 16:51
Experimenting with Paul Blasucci's ideas around Faults and Reports for F#, using the existing F# Result type.
#if INTERACTIVE
#r "nuget: FsToolkit.ErrorHandling"
#endif
open System.Text.Json
open FsToolkit.ErrorHandling
/// All Error DUs should implement this to "take part" in generalised fault reporting.
[<Interface>]
type IFault =
#r "nuget: OpenAI, 2.0.0"
open OpenAI.Chat
open System.Text.Json
open System.Collections.Generic
open System.IO
let client = ChatClient("gpt-4o", "KEY GOES HERE")
module FsOpenAi =
#r "nuget: OpenAI, 2.0.0"
open OpenAI.Chat
let client =
ChatClient("gpt-4o-mini", "API-KEY-GOES-HERE")
//1. Basic call
let response =
client.CompleteChat([ UserChatMessage "Please send a funny greeting back to me!" :> ChatMessage ])
City State Latitude Longitude
MILAN IL 41.453089 -90.5720803
WATERLOO IA 42.492786 -92.3425775
JACKSON TN 35.6145169 -88.81394689999999
BIRMINGHAM AL 33.5185892 -86.8103567
SPARKS NV 39.5349112 -119.7526886
NEWTON NC 35.6698552 -81.22147079999999
DENVER CO 39.7392358 -104.990251
TERRE HAUTE IN 39.4667034 -87.41390919999999
FLORENCE KY 38.9989499 -84.62661109999999
@isaacabraham
isaacabraham / efcoresample.fsx
Last active September 13, 2024 11:44
EF Core 8 and F#
#r "nuget:Microsoft.EntityFrameworkCore.SqlServer, 8.0.8"
open Microsoft.EntityFrameworkCore
open System
open System.Linq
// Our domain model with a custom wrapped ID type
type Id<'T> =
| Id of Guid
@isaacabraham
isaacabraham / Linqoo.fsx
Last active June 10, 2024 10:48
An implementation of LINQ using OO composition features.
module LinqOo =
/// Selects a value into another shape.
type ISelectable<'a, 'b> =
abstract Select: 'a -> 'b
/// Filters a value.
type IFilterable<'a> =
abstract Filter: 'a -> bool
type ICollectable<'a, 'b> =
@isaacabraham
isaacabraham / paket.dependencies
Created June 5, 2024 13:54
App Insights lock
source https://api.nuget.org/v3/index.json
framework: net8.0
storage: none
nuget Microsoft.ApplicationInsights.Profiler.AspNetCore
// A generic Record
type Person<'T> = {
Name: string
Age: int
Singleton: 'T -> 'T list
}
// Creating a value with an "open" generic argument (?)
let personRec : Person<'T> = {
Name = "Isaac"
@isaacabraham
isaacabraham / aps.fsx
Last active February 3, 2025 04:01
Active Patterns
open System
let s = "Card 1: 41 48 83 86 17 | 83 86 6 31 17 9 48 53"
// challenge - split above into values we can reason about e.g.
type Card = {
Id : int // 1
Winning : int list // 41 48 83 86 17
Ticket : int list // 83 86 6 31 17 9 48 53
}