how to resolve use of operators in type declaration (Repa) ?

空扰寡人 提交于 2020-01-06 19:33:00

问题


I am playing around with Repa, and the code below can compile and run.

import qualified Data.Array.Repa as R
--t:: R.Array R.U (R.Z R.:. Int) Float 
--t =  R.fromListUnboxed (R.Z R.:. (10::Int)) ([1.0..10]::[Float])

main = do 
   let x = R.fromListUnboxed (R.Z R.:. (10::Int)) ([1.0..10]::[Float])
   print x

I believe (from check in ghci) that x has the type signature that I have declared t to have, but I get this error if I uncomment everything associated with t:

Illegal operator ‘R.:.’ in type ‘R.Z R.:. Int’
  Use TypeOperators to allow operators in types

what is the correct way to resolve the use of an type operator/constructor in type declarations? (I will google some more, but would like to ask anyway too learn more)


回答1:


You can use the command line option -XTypeOperators to either ghc or ghci, e.g.:

ghci -XTypeOperators ...

Or you can use the OPTIONS_GHC pragma in your source file:

{-# OPTIONS_GHC -XTypeOperators #-}

I'm not sure why LANGUAGE TypeOperators is not recognized.

or the LANGUAGE pragma:

{-# LANGUAGE TypeOperators #-}

(make sure to spell it correctly.)

In this case the type of t is inferable, so you can use :t in ghci:

$ ghci
Prelude> import qualified Data.Array.Repa as R
Prelude R> let t =  R.fromListUnboxed (R.Z R.:. (10::Int)) ([1.0..10]::[Float])
Prelude R> :t t
t :: R.Array R.U (R.Z R.:. Int) Float

Note: I'm using GHC 7.10.2.



来源:https://stackoverflow.com/questions/33566889/how-to-resolve-use-of-operators-in-type-declaration-repa

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!