Consider this Swift:
let addr: String? = person?.job?.address
In this case, if person is nil, it returns nil, otherwise it bind
s the job
, and repeats.
This same thing is expressed in Haskell as:
// | |
// main.c | |
// randomseed | |
// | |
// Created by Harlan Haskins on 1/10/16. | |
// Copyright © 2016 Harlan. All rights reserved. | |
// | |
#include <stdlib.h> | |
#include <stdio.h> |
package cunn not found! | |
package cutorch not found! | |
Falling back on CPU mode | |
creating an rnn... | |
missing seed text, using uniform probability over first character | |
-------------------------- | |
ghedilite. | |
Wertce tirkly and sprinkle to the mixture and stir cold water, purnith for atili ex13 in is remaining whipped mixing bowl, combine brown sugar | |
1 teaspoon ground chilled, warm boiling water (or a skillet thinly fresh fish in 1/8 inch pieces cream cheese, soy cake stuf cheese, karnish with thick)s, about 40 minutes to rice. | |
Place a thinly add to stor lightly tf with chicken parted to sauce |
; ModuleID = '/Users/harlanhaskins/fact.ltr' | |
target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128" | |
target triple = "x86_64-apple-darwin15.0.0" | |
@printformat = private constant [3 x i8] c"%d\00", align 1 | |
@printlnformat = private constant [4 x i8] c"%d\0A\00", align 1 | |
declare i64 @printf(i8*, ...) | |
define private i64 @print(i64 %arg) { |
; ModuleID = 'fact.ltr' | |
target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128" | |
target triple = "x86_64-apple-darwin15.0.0" | |
; Function Attrs: nounwind readnone | |
define i64 @main() #0 { | |
entry: | |
ret i64 0 | |
} |
// note the signature => (T?, T -> U?) -> U? | |
func flatMap<T, U>(value: T?, transform: T -> U?) -> U? { | |
switch value { | |
case .None: return .None | |
case .Some(let contained): return transform(contained) | |
} | |
} | |
// different from this => (T?, T -> U) -> U? | |
func map<T, U>(value: T?, transform: T -> U) -> U? { |
Consider this Swift:
let addr: String? = person?.job?.address
In this case, if person is nil, it returns nil, otherwise it bind
s the job
, and repeats.
This same thing is expressed in Haskell as:
var str = "Hello, playground" | |
public extension String { | |
public func replacing(range: CountableClosedRange<Int>, with replacementString: String) -> String { | |
let start = characters.index(characters.startIndex, offsetBy: range.lowerBound) | |
let end = characters.index(start, offsetBy: (range.upperBound + 1) - range.lowerBound) | |
return self.replacingCharacters(in: start ..< end, with: replacementString) | |
} | |
} |
struct StackFrame { | |
let symbol: String | |
let file: String | |
let address: UInt64 | |
let symbolAddress: UInt64 | |
var demangledSymbol: String { | |
return _stdlib_demangleName(symbol) | |
} | |
} |
import Foundation | |
enum Relation<T> where T: Strideable { | |
case equal(T) | |
case greater(T) | |
case greaterOrEqual(T) | |
case less(T) | |
case lessOrEqual(T) | |
case between(T, T) | |