[prev in list] [next in list] [prev in thread] [next in thread] 

List:       haskell-cafe
Subject:    [Haskell-cafe] [uvector] derive UA instance for newtype
From:       Khudyakov Alexey <alexey.skladnoy () gmail ! com>
Date:       2009-09-23 18:58:57
Message-ID: 200909232304.58119.alexey.skladnoy () gmail ! com
[Download RAW message or body]

Hello

I want to derive UA instance for newtypes. 

Say I have following newtype:
> newtype Foo a = Foo a

Attempts to derive UA automatically fails because it have associated types. It 
seems that it's not possible to define from outside. However it's possible to 
derive instance in the uvector's internals. 

> deriving instance UAE a   => UAE (Foo a)
> deriving instance UPrim a => UPrim (Foo a)
> 
> instance UPrim a => UA (Foo a) where
>   newtype UArr  (Foo a)   = UAFoo (BUArr (Foo a))
>   newtype MUArr (Foo a) s = MUFoo (MBUArr s (Foo a))
> 
>   lengthU        = primLengthU
>   indexU         = primIndexU
>   sliceU         = primSliceU
>   lengthMU       = primLengthMU
>   newMU          = primNewMU
>   readMU         = primReadMU
>   writeMU        = primWriteMU
>   copyMU         = primCopyMU
>   unsafeFreezeMU = primUnsafeFreezeMU
> 
>   memcpyMU     = primMemcpyMU
>   memcpyOffMU  = primMemcpyOffMU
>   memmoveOffMU = primMemmoveOffMU

Am I moving in right direction and are there other/better solutions to 
problem?

--
  Khudyakov Alexey
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic