dff86d4541c8b79987e984e314cdfec7ab504224
[ghc.git] / testsuite / tests / simplCore / should_compile / T8848.hs
1 {-# OPTIONS_GHC -fno-warn-missing-methods #-}
2 {-# OPTIONS_GHC -fno-warn-redundant-constraints #-}
3 {-# LANGUAGE KindSignatures, GADTs, DataKinds, FlexibleInstances, FlexibleContexts #-}
4
5 module T8848 where
6
7 import qualified Control.Applicative as A
8 import qualified Data.Functor as Fun
9
10 data Nat = S Nat | Z
11
12 data Shape (rank :: Nat) a where
13 Nil :: Shape Z a
14 (:*) :: a -> Shape r a -> Shape (S r) a
15
16 instance A.Applicative (Shape Z) where
17 instance A.Applicative (Shape r)=> A.Applicative (Shape (S r)) where
18 instance Fun.Functor (Shape Z) where
19 instance (Fun.Functor (Shape r)) => Fun.Functor (Shape (S r)) where
20
21 map2 :: (A.Applicative (Shape r))=> (a->b ->c) -> (Shape r a) -> (Shape r b) -> [Shape r c]
22 -- Artifically made recursive so that it won't inline,
23 -- se we can see if the speicalisation happens
24 map2 = \f l r -> (A.pure f A.<*> l A.<*> r) : map2 f l r
25
26 {-# SPECIALIZE map2 :: (a->b->c)
27 -> (Shape (S (S Z)) a )
28 -> Shape (S (S Z)) b
29 -> [Shape (S (S Z)) c] #-}
30
31 map3 :: (a->b->c)-> (Shape (S (S Z)) a )-> Shape (S (S Z)) b -> [Shape (S (S Z)) c]
32 map3 x y z = map2 x y z