haskell - Defining Phantom Types - can't compile examples -


i'm trying learn more phantom types. i'm trying read through fun phantom types ralf hinze. he's using keyword with haven't seen before , can't compile. parse error on = when try this.

data type t = rint                    t = int             | rchar                   t = char             | rlist (type a)          t = [a ]             | rpair (type a) (type b) t = (a, b) 

earlier in paper, says "with" statements aren't strictly necessary, can set a = t instead, can't figure out how define data type without them. following errors with: not in scope: type variable 'a'

data type t = rint             | rchar             | rlist (type a)             | rpair (type a) (type b) 

what missing?

my guess definition sans-with suggested in paper is

data type t = rint             | rchar             | rlist (type t)             | rpair (type t) (type t) 

above, parameter t never used. is, indeed, phantom.

this implies that, e.g.

rint :: type 

for any type a. contrast, if with constraints followed, impossible have rint :: type t t t ~ int.

the with syntax not present in ghc, gadts play same role.

{-# language gadts #-} data type t    rint  :: t ~ int   => type t    rchar :: t ~ char  => type t    rlist :: t ~ [a]   => type -> type t    rpair :: t ~ (a,b) => type -> type b -> type t 

note how with replaced equality constraint in each constructor. it's same thing, written differently.

more compactly, can rewrite above into

data type t    rint  :: type int    rchar :: type char    rlist :: type -> type [a]    rpair :: type -> type b -> type (a,b) 

where constraints have been "inlined" in final type.


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -