Created
August 21, 2018 18:11
-
-
Save kai-qu/5b95f5e7cba7c9186e6e4f5660020dc5 to your computer and use it in GitHub Desktop.
Command: `stack ghc grad.hs -- -Wtype-defaults`
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
{-# LANGUAGE AllowAmbiguousTypes, RankNTypes, NoMonomorphismRestriction, ConstraintKinds #-} | |
-- Minimal AD example with polymorphism. | |
import Numeric.AD | |
type Autofloat a = (RealFloat a, Floating a, Real a, Show a, Ord a) | |
f :: (Autofloat a) => [a] -> a | |
f [x, y] = x^2 + y^2 + 0.1 | |
appGrad :: (Autofloat a) => (forall b . (Autofloat b) => [b] -> b) -> [a] -> [a] | |
appGrad f l = grad f l | |
state :: (Autofloat a) => [a] | |
state = [1.10, -1.2] | |
res = appGrad f state | |
main :: IO () | |
main = putStrLn $ show $ res |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment