forked from ku-fpg/hermit-streamfusion
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Deep.hs
36 lines (26 loc) · 957 Bytes
/
Deep.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE TypeSynonymInstances #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE RankNTypes #-}
{-# OPTIONS_GHC -funbox-strict-fields #-}
{-# OPTIONS_GHC -fspec-constr #-}
{-# OPTIONS_GHC -fdicts-cheap #-}
{-# OPTIONS_GHC -optlo-O3 -optlc-O3 #-} -- this is fast...
module Main where
import Data.Strict.Tuple
import Data.Vector.Fusion.Stream.Monadic as SM
import HERMIT.Optimization.StreamFusion.Vector
main :: IO ()
main = testDeep >>= print
class Deep x where
deep :: x -> SM.Stream IO Int
instance Deep Int where
deep !k = SM.enumFromStepN 1 1 k
{-# INLINABLE deep #-}
instance Deep x => Deep (x :!: Int) where
deep !(x :!: k) = SM.concatMap (SM.enumFromStepN 1 1) $ deep x
{-# INLINABLE deep #-}
testDeep :: IO Int
testDeep = SM.foldl' (+) 0 $ deep (( (10::Int) :!: (12::Int)) :!: (14::Int) :!: (15::Int))
{-# NOINLINE testDeep #-}