[Haskell-cafe] Rigid types fun

2010-11-05 Thread Mitar
Hi!

I have much fun with rigid types, type signatures and GADTs. And I
would like to invite also others in and share my joy. ;-)

Please see the attached file and chase a solution to how to make it
compile. I would like to have a function which I would call like:

createNerve (Axon undefined) (AxonAny undefined)

and it would return proper Nerve. Similar to how asTypeOf works.

I would like to do that to remove repeating code like:

from - newChan
for - newChan
let nerve = Nerve (Axon from) (AxonAny for)

which I have to write again and again just to make types work out. Why
I cannot move that into the function?

I am using GHC 6.12.3. Is this something which will work in 7.0?


Mitar


Test.hs
Description: Binary data
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Rigid types fun

2010-11-05 Thread Tillmann Rendel

Hi,

Mitar wrote:

I would like to do that to remove repeating code like:

from- newChan
for- newChan
let nerve = Nerve (Axon from) (AxonAny for)

which I have to write again and again just to make types work out. Why
I cannot move that into the function?


One option is to write a little library of functions which create axons 
and nerves:


  newAxon :: Impulse i = IO (Axon (Chan i) i AxonConductive)
  newAxon = do
chan - newChan
return (Axon chan)

  newAxonAny :: IO (Axon (Chan i) AnyImpulse AxonConductive)
  newAxonAny = do
chan - newChan
return (AxonAny chan)

  newNoAxon :: Monad m = m (Axon (Chan i) i AxonNotConductive)
  newNoAxon = do
return NoAxon

  newNerve :: Monad m = m (Axon a a' b) - m (Axon c c' d)
- m (Nerve a a' b c c' d)
  newNerve newFrom newFor = do
from - newFrom
for - newFor
return (Nerve from for)

Note that newNerve does not take Axons, but rather monadic actions which 
create Axons. Now, you can use something like


  nerve - newNerve newAxon newAxonAny

to create a concrete nerve.

  Tillmann

PS. It might be an interesting exercise to use either liftM and liftM2 
(from Control.Monad) or the ($) and (*) operators from 
Control.Applicative to implement these functions without do notation.


PPS. Crosspost removed. I don't want to post to mailing lists which I do 
not read.

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Rigid types fun

2010-11-05 Thread Mitar
Hi!

On Fri, Nov 5, 2010 at 4:01 PM, Tillmann Rendel
ren...@informatik.uni-marburg.de wrote:
 Note that newNerve does not take Axons, but rather monadic actions which
 create Axons. Now, you can use something like

  nerve - newNerve newAxon newAxonAny

 to create a concrete nerve.

Thanks! I decided for this approach. It seems to me the nicest. Simple
and allows me to later redefine Nerve and Axon without breaking stuff
around.


Mitar
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe