Created
October 13, 2016 09:36
-
-
Save adicirstei/191946ac1c97490d5af306f607405895 to your computer and use it in GitHub Desktop.
How do I design this?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// My function types | |
type Backward<'Core> = 'Core -> 'Core | |
type InputCore = { | |
backward : Backward<InputCore> | |
x : float | |
} | |
type TanhCore = { | |
backward : Backward<TanhCore> | |
y : float | |
} | |
type Layer = | |
| Input of InputCore | |
| Tanh of TanhCore | |
module Input = | |
let backward c = // do some core specific computation | |
{ c with x = c.x * 3.423 } | |
module Tanh = | |
let backward c = // do some core specific computation | |
{ c with x = c.y * c.y } | |
/// Now, having a list of varoius Layer type instances, I want to call the `backward` | |
// function on every of them without matching on each. | |
let backward (lst:Layer list) = | |
lst | |
|> List.map (fun l -> | |
match l with | |
| Input core -> Input.backward core | |
| Tanh core -> Tanh.backward core | |
) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment