79425117

Date: 2025-02-09 15:09:50
Score: 0.5
Natty:
Report link

The launchMissilesAt example would in F# be something like:

type Country = BigEnemy | MediumEnemy | PunyEnemy | TradePartner | Ally | BestAlly

let launchMissilesAt country =
    printfn "bombed %A" country

(*
GFunc
type GFunc<'R> =
    abstract Invoke : 'T -> 'R
*)

// inspired by GFunc 
type ElementPicker =
    abstract Pick : 'T list -> 'T

let g =
    {new ElementPicker with
        member this.Pick(xs) = xs |> List.head }    // or something alike

//let g =
//    {new ElementPicker with
//        member this.Pick(_) = BestAlly }
//This expression was expected to have type
//    ''a'    
//but here has type
//    'Country'    

let f = launchMissilesAt <| g.Pick [BigEnemy; MediumEnemy; PunyEnemy]
Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Unregistered user (0.5):
  • Low reputation (1):
Posted by: Ed van Gageldonk