Tuesday, October 25, 2016

Good deal tomorrow on Alaska business class flight tomorrow with miles LAX -> LHR

Found this one browsing around Alaska's flights, figuring out a trip for next year - 50k miles for a business class ticket LAX -> LHR seems like a really good deal to me:




Tuesday, June 21, 2016

Xamarin Studio + Android Studio

If you have a Xamarin Studio project for an Android application, you'll probably want to use Android Studio to edit the resource files.
  • Create a new Android Studio project (I usually call it AndroidStudioHolder, but the name is unimportant)
  • cd AndroidStudioHolder/app/src/main
  • rm -rf res
  • ln -s ../../../../YourAndroidProject/Resources res
Unfortunately, you still have to deal with all the weird naming issues that Xamarin Studio creates.  You should fix them anyway, and it's easier to do it early in the project.  (Main.axml isn't a real layout file, for example, even though Xamarin Studio will create it for you by default.)

Thursday, May 26, 2016

Using F# modules and types from C#

It's simple to use FSharp modules from C#, but for some reason I always forget exactly how the system works
(maybe too much switching back and forth between Scala/C#/F#/Java...).

Here's some F# snippets and a C# example of how to pull them together. The weird one is C#'s "using static", since the name seems to indicate that it's just pulling in static methods. In addition to pulling in static methods, though, it also pulls in nested types.

namespace FSharpNamespace
type Class2 =
| Something
| OtherThing of int


module FSharpModule
let fn() = 1
type Class1() =
member this.X = "F#"


using System;
// Note that "using FSharpModule" (without "static") isn't legal C#.
// An FSharp module gets compiled into a type, and "using" specifically
// imports namespaces.
using static FSharpModule;
using FSharpNamespace;
using static FSharpNamespace.Class2;
#pragma warning disable 219 // no warnings about unused variables
namespace ConsoleSample
{
class MainClass
{
public static void Main (string [] args)
{
int a = FSharpModule.fn ();
FSharpModule.Class1 b = new FSharpModule.Class1 ();
// using static FSharpModule means we don't have to
// write "FSharpModule." before our types
int c = fn ();
Class1 d = new Class1 ();
FSharpNamespace.Class2 e = FSharpNamespace.Class2.Something;
Class2 f = Class2.Something;
// Allowed by "using static FSharpNamespace.Class2"
Class2 g = Something;
Class2 h = NewOtherThing (1);
}
}
}
view raw main.cs hosted with ❤ by GitHub


Consuming from F# is slightly simpler:

module FSharpConsumer
let a = FSharpNamespace.Class2.Something;
// Notice that in F# we use "open" for both modules and namespaces.
// See the F# spec section 14.1.3 Opening Modules and Namespace Declaration Groups
// for precise details.
open FSharpNamespace
let b = Class2.Something;
let c = Something;
let d: FSharpModule.Class1 = FSharpModule.Class1();
open FSharpModule
let e = fn()
let f = new Class1();


Here's the F# specification for more details.

Wednesday, February 10, 2016

Fun with Shapeless - functions taking arguments converted to functions taking HList's

I'm starting to play with the Shapeless Scala library.

Here's how to take a normal function and turn it into a function that accepts an HList instead of the original arguments.

scala> import shapeless._
import shapeless._
scala> import shapeless.ops.function.FnToProduct
import shapeless.ops.function.FnToProduct
scala>
scala> // a normal function taking a string and returning 42
scala> def fn1(a: String) = 42
fn1: (a: String)Int
scala>
scala> /**
| * A function that takes a function that takes arguments and returns
| * a function taking a single HList.
| *
| * @param fn The function to convert. Notice that the type is just F; the heavy lifting is done by implicit resolution
| * @param fnToProduct The tool you use to convert functions taking arguments to functions taking HLists
| * @tparam F The type of the input function
| * @tparam L Used by FnToProduct.Aux
| * @tparam R Used by FnToProduct.Aux
| * @return
| */
| def convertToFunctionTakingHList[F, L <: HList, R](fn: F)(implicit fnToProduct: FnToProduct.Aux[F, L => R]): fnToProduct.Out = fnToProduct(fn)
convertToFunctionTakingHList: [F, L <: shapeless.HList, R](fn: F)(implicit fnToProduct: shapeless.ops.function.FnToProduct.Aux[F,L => R])fnToProduct.Out
scala>
scala> val fn2: FnToProduct.Aux[(String) => Int, (::[String, HNil]) => Int]#Out = convertToFunctionTakingHList(fn1 _)
fn2: shapeless.::[String,shapeless.HNil] => Int = <function1>
scala> val result = fn2("a string" :: HNil)
result: Int = 42
view raw gistfile1.scala hosted with ❤ by GitHub