Skip to content

Instantly share code, notes, and snippets.

giuliohome

Block or report user

Report or block giuliohome

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@giuliohome
giuliohome / simple_wcf.fs
Last active Nov 6, 2016 — forked from dgfitch/simple_wcf.fs
A sample WCF host and client in F#, extremely simple but a starting point
View simple_wcf.fs
open System
open System.ServiceModel
open System.ServiceModel.Description
[<ServiceContract(ConfigurationName = "PublishService", Namespace = "http://xyz.gov/PublishService")>]
[<ServiceBehavior(InstanceContextMode=InstanceContextMode.PerSession)>]
type IPublishService =
[<OperationContract(Name="TestMethod")>]
abstract member TestMethod : name:string -> string
View Transducer.cs
using System;
using System.Collections.Generic;
using System.Linq;
using TransducersNet;
namespace TransducerSample2CSharp
{
class Program
{
private static IEnumerable<string> asStream(string[] iterable)
View datarow.fs
// https://dotnetfiddle.net/sjSjeS
open System
open System.Data
open System.Xml
open Microsoft.FSharp.Linq
type RowReader(reader:DataRow) =
member private x.Reader = reader
static member (?) (x:RowReader, name:string) : 'R =
@giuliohome
giuliohome / io.fsx
Created Jun 6, 2017 — forked from battermann/io.fsx
IO Monad in F#
View io.fsx
[<AutoOpen>]
module IO =
type IO<'a> =
private
| Return of (unit -> 'a)
| Suspend of (unit -> IO<'a>)
let rec run x =
match x with
| Return v -> v()
View gist:104185116b28273403cb2b6ba6cec210
type TrimNonEmptyString internal (value : string) =
member __.Value = value
override __.ToString() = value
override __.Equals(yobj) =
match yobj with
| :? TrimNonEmptyString as y -> (__.Value = y.Value)
| _ -> false
override __.GetHashCode() = hash value
static member TryParse (value : string) =
if System.String.IsNullOrWhiteSpace value then
@giuliohome
giuliohome / free.fsx
Created Aug 1, 2017 — forked from battermann/free.fsx
Free Monad like pattern in F#
View free.fsx
#load @"paket-files/fsprojects/Chessie/src/Chessie/ErrorHandling.fs"
type Continuation<'output, 'next> = 'output -> 'next
module TerminalDsl =
open Chessie.ErrorHandling
type Terminal<'next> =
| WriteLine of string * Continuation<unit, 'next>
| ReadLine of unit * Continuation<string, 'next>
@giuliohome
giuliohome / Primes.hs
Created Dec 29, 2017
Applying f-algebras to primes
View Primes.hs
{-# LANGUAGE DeriveFunctor #-}
-- https://bartoszmilewski.com/2017/02/28/f-algebras/
newtype Fix f = Fix (f (Fix f))
unFix :: Fix f -> f (Fix f)
unFix (Fix x) = x
cata :: Functor f => (f a -> a) -> Fix f -> a
cata alg = alg . fmap (cata alg) . unFix
ana :: Functor f => (a -> f a) -> a -> Fix f
@giuliohome
giuliohome / dsl.hs
Created Dec 30, 2017
A complete example of DSL in Haskell
View dsl.hs
{-# LANGUAGE DeriveFunctor #-}
-- {-# LANGUAGE GeneralizedNewtypeDeriving #-}
-- {-# LANGUAGE XRankNTypes #-}
-- run this online https://repl.it/repls/GraciousCooperativeNijssenissdwarfchihlid
import Control.Applicative -- <$>
import Control.Monad
data Free f r = Free (f (Free f r)) | Pure r
View FindAllBestChains.hs
{-# LANGUAGE DeriveFunctor #-}
-- Is there a trick to getting this done easier?
-- yep, look at TryAgainFromScratch.hs
module Bridge where
import Data.List
import Data.Ord
import qualified Data.Map as Map
@giuliohome
giuliohome / Hylo.fs
Created Feb 19, 2018 — forked from CarstenKoenig/Hylo.fs
Factorial using a Hylomorphism in F#
View Hylo.fs
type List<'i,'r> = Nil | Cons of 'i*'r
type FixList<'i> = FixList of List<'i,FixList<'i>>
let rec fmap (f : 'a -> 'b) (l : List<'i,'a>) : List<'i,'b> =
match l with
| Nil -> Nil
| Cons (x, tail) -> Cons (x, f tail)
// you can express hylo directly without using ana and cata (by either following the
You can’t perform that action at this time.