Created
August 21, 2018 18:12
-
-
Save kai-qu/786fa0fd46b9a2fa387e806f6bee3cbb 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 | |
{- Result: | |
grad.hs:10:12: warning: [-Wtype-defaults] | |
• Defaulting the following constraints to type ‘Integer’ | |
(Integral b0) arising from a use of ‘^’ at grad.hs:10:12-14 | |
(Num b0) arising from the literal ‘2’ at grad.hs:10:14 | |
• In the first argument of ‘(+)’, namely ‘x ^ 2’ | |
In the first argument of ‘(+)’, namely ‘x ^ 2 + y ^ 2’ | |
In the expression: x ^ 2 + y ^ 2 + 0.1 | |
grad.hs:10:18: warning: [-Wtype-defaults] | |
• Defaulting the following constraints to type ‘Integer’ | |
(Integral b0) arising from a use of ‘^’ at grad.hs:10:18-20 | |
(Num b0) arising from the literal ‘2’ at grad.hs:10:20 | |
• In the second argument of ‘(+)’, namely ‘y ^ 2’ | |
In the first argument of ‘(+)’, namely ‘x ^ 2 + y ^ 2’ | |
In the expression: x ^ 2 + y ^ 2 + 0.1 | |
grad.hs:21:19: warning: [-Wtype-defaults] | |
• Defaulting the following constraints to type ‘Double’ | |
(Show a0) arising from a use of ‘show’ at grad.hs:21:19-28 | |
(RealFloat a0) arising from a use of ‘res’ at grad.hs:21:26-28 | |
• In the second argument of ‘($)’, namely ‘show $ res’ | |
In the expression: putStrLn $ show $ res | |
In an equation for ‘main’: main = putStrLn $ show $ res | |
-} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment