Google Groups Home Help | Sign in
Higher-order kinds?
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  1 message - Collapse all
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
Jacques Carette  
View profile
 More options Nov 9 2006, 4:47 pm
Newsgroups: fa.caml
From: Jacques Carette <care...@mcmaster.ca>
Date: Thu, 09 Nov 2006 21:47:54 UTC
Local: Thurs, Nov 9 2006 4:47 pm
Subject: [Caml-list] Higher-order kinds?
Is there any way to get higher-order kinds in Ocaml?

While investigating some issues around partial evaluation (in
MetaOCaml), we ran across this post from Jacques Guarrigue:

http://caml.inria.fr/pub/ml-archives/caml-list/2006/09/05dcdcb7064cc7...

After a few emails between Ken Shan and Oleg Kiselyov, Ken produced a very elegant translation of this 'trick' into Haskell, which starts off thus:

data T f = Bool (f Bool) | Int (f Int) | Fun (T (F1 f))
newtype F1 f a = F1 { f1 :: T (F2 f a) }
newtype F2 f a b = F2 { f2 :: f (a -> b) }

Note how f in the above it a type-level function, and the types F1 and
F2 are used 'partially applied'.  It is possible to expand this all out
into first-order, but the end result is not pretty, to say the least!

Note that the rest of the Haskell code (classes and instances) can be
translated into Functors and Modules [using that nice trick of having
functors that produce module types, again thanks to Jacques G.].  The
end result is definitely more verbose than the Haskell, but not
desperately so.

Jacques

PS: rest of code, which just implements in an 'open' way what Jacques G.
did using closed types in the email linked-to above

class Dynamic t where
    inj :: f t -> T f
    prj :: T f -> Maybe (f t)

instance Dynamic Bool where
    inj = Bool
    prj (Bool x) = Just x
    prj _ = Nothing

instance Dynamic Int where
    inj = Int
    prj (Int x) = Just x
    prj _ = Nothing

instance (Dynamic a, Dynamic b) => Dynamic (a -> b) where
    inj x = Fun (inj (F1 (inj (F2 x))))
    prj (Fun t) = prj t >>= prj . f1 >>= return . f2
    prj _ = Nothing

_______________________________________________
Caml-list mailing list. Subscription management:
http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
Archives: http://caml.inria.fr
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs


    Reply to author    Forward  
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.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2008 Google