Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion C representation and further plans
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Roman Cheplyaka  
View profile  
 More options Mar 22 2011, 2:50 am
From: Roman Cheplyaka <r...@ro-che.info>
Date: Tue, 22 Mar 2011 08:50:33 +0200
Local: Tues, Mar 22 2011 2:50 am
Subject: Re: [loker] C representation and further plans
* Alexander Batischev <eual...@gmail.com> [2011-03-21 23:26:54+0200]

> On Mon, Mar 21, 2011 at 10:01:35PM +0200, Roman Cheplyaka wrote:
> > * Alexander Batischev <eual...@gmail.com> [2011-03-21 21:00:16+0200]
> > > On Mon, Mar 21, 2011 at 08:25:35AM +0200, Roman Cheplyaka wrote:
> > > > * Alexander Batischev <eual...@gmail.com> [2011-03-21 01:27:31+0200]
> > > > > IR2C.hs:23:0:
> > > > >     Couldn't match expected type `ArrayNT CChar'
> > > > >            against inferred type `ArrayNT CString'
> > > > >     When generalising the type(s) for `translateStatement'

> > > > That's my fault. If you look at C.hs, you'll find this line:

> > > >     type ExprType NULL = CString -- do we need NULL for anything else?

> > > > Apparently we do! :)

> > > I can't figure out how should I fix that. ExprType just binds internal
> > > (Haskell) types with their C analogs, and it seems that NULL can't be
> > > expressed in any of them. I would be happy to write something like:

> > >     instance CExpr t => CExpr NULL
> > >       where
> > >       type CExpr NULL = ArrayNT t

> > > but I can't:

> > > C.hs:88:33: Not in scope: type variable `t'

> > > (so type variables should be used in the type signature - or it would be
> > > out of scope).

> > > Any advice?

> > Yes -- you need to annotate the NULL datatype with its C type, just as
> > it is done for CVariable.

> Still don't get it. I tried to declare new CNull type and add the
> following CExpr instance:

>     data CNull

>     instance CExpr NULL
>         where
>         type ExprType NULL =  CNull
>         printExpr _ = PrettyC.nullLiteral

Sorry, perhaps I was not clear.

Currently we have

    data NULL = NULL

Your problem is that in CExpr declaration you cannot infer the type of
NULL, so until now we have assumed that it is a CString.

What you can do instead is add a type parameter to NULL:

    data NULL t = NULL

(compare with CVariable declaration).

Now the same data constructor NULL carries the information about its C
type, so you can define in the CExpr instance

  type ExprType (NULL t) = t

This technique is called phantom types[1].

[1]: http://www.haskell.org/haskellwiki/Phantom_type

--
Roman I. Cheplyaka :: http://ro-che.info/
Don't worry what people think, they don't do it very often.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.