Skip to content

Instantly share code, notes, and snippets.

View mgadda's full-sized avatar

Matt Gadda mgadda

View GitHub Profile
@mgadda
mgadda / navigation_link.swift
Last active December 26, 2022 18:22
NavigationLink issues
protocol IO {
associatedtype CollectionType: Collection
init(_ source: CollectionType)
func go() -> AnyCollection<CollectionType.Element>
}
struct Print<T> : IO where T: Collection {
typealias CollectionType = T
let source: CollectionType
init(_ source: T) {
@mgadda
mgadda / IO.swift
Last active December 31, 2019 17:20
//
// reduced_problem.swift
// swift-parse-playground
//
// Created by Matt Gadda on 12/27/19.
//
typealias IO<InputElement, OutputElement> = (AnyCollection<InputElement>) -> AnyCollection<OutputElement>?
func printConsumer<T: Collection>(_ source: T) -> AnyCollection<T.Element>? {
typealias Parser<T: Collection, U, T2> = (T) -> (U, T2)?
typealias StandardParser<T: Collection, U> = Parser<T, U, T>
typealias HomogeneousParser<T: Collection> = StandardParser<T, T>
protocol ParserConvertible {
associatedtype InputType : Collection = Self
associatedtype ParsedValueType = Self
associatedtype OutputType = Self
func mkParser() -> Parser<InputType, ParsedValueType, OutputType>
@mgadda
mgadda / Bar.swift
Last active January 14, 2017 16:42
Example which causes swiftc to hang
typealias Bar = Foo<Int>
@mgadda
mgadda / write_to_immutable_array.swift
Created January 11, 2017 19:35
How to write to an immutable array
let immutable = Array<Int32>(repeating: 0, count: 4) // => [0, 0, 0, 0]
let ptr = UnsafeMutablePointer<Int32>(mutating: immutable)
let mutableBuffer = UnsafeMutableBufferPointer(start: ptr, count: immutable.count * MemoryLayout<Int32>.size)
let data: Data = Data(bytes: [
0, 0, 0, 0,
1, 0, 0, 0,
2, 0, 0, 0,
3, 0, 0, 0])
data.copyBytes(to: mutableBuffer)
immutable // => [0, 1, 2, 3]
@mgadda
mgadda / output.log
Last active January 2, 2017 22:20
A simple but likely not fully distilled code snippet which produces swiftc segfault
> swiftc main.swift
0 swift 0x00000001094d13ad PrintStackTraceSignalHandler(void*) + 45
1 swift 0x00000001094d0b56 SignalHandler(int) + 790
2 libsystem_platform.dylib 0x00007fffa03fcbba _sigtramp + 26
3 libsystem_platform.dylib 0x00007fdef523a8a8 _sigtramp + 1424219400
4 swift 0x00000001066b979c swift::ASTVisitor<(anonymous namespace)::SILGenApply, void, void, void, void, void, void>::visit(swift::Expr*) + 4492
5 swift 0x00000001066be19e (anonymous namespace)::SILGenApply::visitApplyExpr(swift::ApplyExpr*) + 5166
6 swift 0x00000001066ac5f1 prepareApplyExpr(swift::Lowering::SILGenFunction&, swift::Expr*) + 273
7 swift 0x00000001066fd8b7 swift::ASTVisitor<(anonymous namespace)::RValueEmitter, swift::Lowering::RValue, void, void, void, void, void, swift::Lowering::SGFContext>::visit(swift::Expr*, swift::Lowering::SGFContext) + 103
8 swift 0x000000010675dfaa swift::Lowerin
@mgadda
mgadda / IO.swift
Last active December 17, 2016 04:50
typealias RealWorld = Int
typealias IO<T> = (RealWorld) -> (T, RealWorld)
func putStrLn(_ str: String) -> IO<()> {
return { (world) in
print(str)
return ((), world + 1)
}
}
@mgadda
mgadda / domEventHandlers.elm
Last active December 5, 2016 01:34
Conditional event handlers for key presses
module Util exposing (..)
import Html.Events exposing (on, keyCode)
import Html exposing (Attribute)
import Json.Decode as Json
import Dict exposing (Dict)
{-| Conditionally emit msg defined by `tagger` if the
key pressed was the enter key. Cannot be used with onEscape.
@mgadda
mgadda / .flowconfig
Created June 30, 2016 14:16
Why does line 16 of index.js produce a Flow error?
[ignore]
[include]
[libs]
[options]