Skip to content

Instantly share code, notes, and snippets.

@aaronlevin
aaronlevin / events.hs
Last active December 3, 2023 13:03
LambdaWorld 2016 & Typelevel Summit 2017 (Copenhagen): Type-Level DSLs // Typeclass induction
-- Our goal is to create a type describing a list of events. This is our
-- type-level DSL.
-- We will then use typeclass resolution to "interpret" this type-level DSL
-- into two things:
-- 1. A comma-separated list of events
-- 2. A method that, when given an event name and a payload, will try to parse
-- that event type with the payload. A form of dynamic dispatching
--
-- To model a list of types we will use tuples. You can imagine the list of
-- types "Int, String, Char" to look like:

Applied Functional Programming with Scala - Notes

Copyright © 2016-2018 Fantasyland Institute of Learning. All rights reserved.

1. Mastering Functions

A function is a mapping from one set, called a domain, to another set, called the codomain. A function associates every element in the domain with exactly one element in the codomain. In Scala, both domain and codomain are types.

val square : Int => Int = x => x * x
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE OverlappingInstances #-}
module Main where
import Control.Monad.Free
@davidfowl
davidfowl / Example1.cs
Last active September 2, 2024 12:36
How .NET Standard relates to .NET Platforms
namespace Analogy
{
/// <summary>
/// This example shows that a library that needs access to target .NET Standard 1.3
/// can only access APIs available in that .NET Standard. Even though similar the APIs exist on .NET
/// Framework 4.5, it implements a version of .NET Standard that isn't compatible with the library.
/// </summary>INetCoreApp10
class Example1
{
public void Net45Application(INetFramework45 platform)
@loicdescotte
loicdescotte / PlayAkkaSourceQueue.scala
Last active April 26, 2024 07:30
Play and Akka Streams source queue
class Application @Inject() (implicit actorSystem: ActorSystem, exec: ExecutionContext) extends Controller {
implicit val materializer = ActorMaterializer()
val Tick = "tick"
class TickActor(queue: SourceQueue[String]) extends Actor {
def receive = {
case Tick => queue.offer("tack")
}
@yang-wei
yang-wei / destructuring.md
Last active December 2, 2024 06:40
Elm Destructuring (or Pattern Matching) cheatsheet

Should be work with 0.18

Destructuring(or pattern matching) is a way used to extract data from a data structure(tuple, list, record) that mirros the construction. Compare to other languages, Elm support much less destructuring but let's see what it got !

Tuple

myTuple = ("A", "B", "C")
myNestedTuple = ("A", "B", "C", ("X", "Y", "Z"))

Maxpath and .NET

Changes to .NET Core now allow for longer paths for directories. Here's a sample showcasing that.

Note: this sample is running on .NET Core. The easiest way to get going with that is to get the bits, create these files in a directory, and open that directory with Visual Studio Code.

To build and run:

$ dnu restore
Function GenerateDSC {
$WindowsFeature = Get-WindowsFeature | Where {$PSItem.installed -and $PSItem.name -match 'net-framework'} | % {
@"
WindowsFeature $($PSItem.name) {
Ensure = 'Present'
Name = "$($PSItem.name)"
}
Configuration DotNetFrameWork{
param($TargetMachine)
Node $TargetMachine {
WindowsFeature NET-Framework-Features {
Ensure = 'Present'
Name = "NET-Framework-Features"
}
@Horusiath
Horusiath / Program.fs
Created July 13, 2015 08:30
Akkling perisistence example
open System
open System.Threading
open Akkling
open Akkling.Persistence
let system = System.create "persistent-system" (Configuration.defaultConfig())
type Event =
| Added of int
| Removed of int