Skip to content

Instantly share code, notes, and snippets.

@mchakravarty
mchakravarty / CountingEditorApp.swift
Created September 9, 2020 13:50
SwiftUI AttributeGraph cycle in playground only
// Put this into an Xcode 12.0 multiplatform app
import SwiftUI
struct ContentView: View {
@State var text = "Hello!"
var body: some View {
VStack {
TextEditor(text: $text)
infix operator ?! { }
func ?!<A>(v: A?, msg: String) -> A {
if let v = v {
return v
} else {
println(msg)
exit(1)
}
}

Keybase proof

I hereby claim:

  • I am mchakravarty on github.
  • I am tacticalgrace (https://keybase.io/tacticalgrace) on keybase.
  • I have a public key whose fingerprint is 234C FFAE 8B87 C024 2C6B 8DD4 888F 3E64 4E8B F866

To claim this, I am signing this object:

@mchakravarty
mchakravarty / ylj14-instructions.md
Last active August 29, 2015 14:01
YOW! Lambda Jam 2014 — Foreign Inline Code in Haskell — Instructions for the workshop

Installation instructions

Prerequisites: OS X with the latest Xcode and command line tools installed (or just the command line tools)

(If you haven't got a machine with OS X, please pair up with a participant who has got a Mac at the workshop.)

Install the Haskell Platform (2013.2.0.0, 64 bit): http://www.haskell.org/platform/mac.html (Note the special installation instructions for using the Haskell Platform with Xcode 5.)

Now, that you have got a Haskell system, install language-c-inline, the library implementing inline C code for Haskell.

@mchakravarty
mchakravarty / ghc7.6-clang-error.log
Last active December 22, 2015 06:29
I am trying to compile GHC HEAD from today (4 Sep) with the command line tools of Xcode5-DP6, using GHC 7.6.3 of the current Haskell Platform. I'm using the clang-xcode5-wrapper from GHC iOS, so that GHC 7.6 can be friends with clang's cpp. Unfortunately, it doesn't work. I have tracked it down to GHC trying to compute module dependencies (-M) a…
"/usr/bin/ghc" -M -static -H32m -O -Werror -Wall -H64m -O0 -package-db libraries/bootstrapping.conf -package-name Cabal-1.18.0 -hide-all-packages -i -ilibraries/Cabal/Cabal/. -ilibraries/Cabal/Cabal/dist-boot/build -ilibraries/Cabal/Cabal/dist-boot/build/autogen -Ilibraries/Cabal/Cabal/dist-boot/build -Ilibraries/Cabal/Cabal/dist-boot/build/autogen -Ilibraries/Cabal/Cabal/. -optP-include -optPlibraries/Cabal/Cabal/dist-boot/build/autogen/cabal_macros.h -package array-0.4.0.1 -package base-4.6.0.1 -package bytestring-0.10.0.2 -package containers-0.5.0.0 -package deepseq-1.3.0.1 -package directory-1.2.0.1 -package filepath-1.3.0.1 -package pretty-1.1.1.0 -package process-1.1.0.2 -package time-1.4.0.1 -package unix-2.6.0.1 -Wall -fno-ignore-asserts -fwarn-tabs -XHaskell98 -XCPP -fno-warn-deprecated-flags -no-user-package-db -rtsopts -w -odir libraries/Cabal/Cabal/dist-boot/build -hidir libraries/Cabal/Cabal/dist-boot/build -stubdir libraries/Cabal/Cabal/dist-boot/build -dep-makefile libraries/Cabal/Ca
@mchakravarty
mchakravarty / Exp.hs
Created August 25, 2013 05:20
Functorial approach to defining expressions.
data PreExp exp = Val Int
| Add exp exp
newtype Exp = Exp (PreExp Exp) -- this is just a normal expression
data AttrExp = AttrExp Attr (PreExp AttrExp) -- an attributed expression
data Attr = ...
@mchakravarty
mchakravarty / BezierVec.hs
Created July 18, 2013 03:14
Arbitrary-dimensional bezier curves with statically checked consistency of dimensions. This is a variant of https://github.com/hrldcpr/Bezier.hs using type-indexed lists (aka vectors) implemented with GADTs and data kinds.
{-# LANGUAGE GADTs, DataKinds, KindSignatures, StandaloneDeriving #-}
module BezierVec (bezier) where
infixr :::
-- encoding of natural numbers (zero and successor of a natural)
data Nat = Z | S Nat
-- indexed vectors are lists whose first type argument encodes the length of the list
{-# LANGUAGE TemplateHaskell, QuasiQuotes #-}
module TestInlineObjC (objc_initialise, dumpURL) where
import Language.C.Quote.ObjC
import InlineObjC
objc_import ["<Foundation/Foundation.h>"]
@mchakravarty
mchakravarty / InlineObjC.hs
Created January 25, 2013 07:42
Example of how inline Objective-C in Haskell might look like.
dumpURL :: String -> IO ()
dumpURL urlString
= do
{ urlData <- $objc 'urlString [cstm| {
return [NSString stringWithContentsOfURL: [NSURL urlWithString: urlString]
encoding: NSUTF8StringEncoding
error: NULL];
} |]
; putStr urlData
}

Welcome to Drift!

Drift is an always-already versioned, cloud-backed text editor. You can use it to take notes, and save them in the GitHub cloud.

Your gists are always saved locally, and any changes you make will get pushed to GitHub's servers.

To name a gist, touch its name in the toolbar.

You can use the share button at the top-right to copy a link to one of your gists, or view it on the web in Safari.