Skip to content

GitLab

  • Projects
  • Groups
  • Snippets
  • Help
    • Loading...
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in
C
compiler
  • Project overview
    • Project overview
    • Details
    • Activity
    • Releases
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 18
    • Issues 18
    • List
    • Boards
    • Labels
    • Service Desk
    • Milestones
  • Operations
    • Operations
    • Incidents
  • Analytics
    • Analytics
    • Repository
    • Value Stream
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Members
    • Members
  • Activity
  • Graph
  • Create a new issue
  • Commits
  • Issue Boards
Collapse sidebar
  • clean-compiler-and-rts
  • compiler
  • Issues
  • #61

Closed
Open
Opened Feb 19, 2020 by Mart Lubbers@mlubbersDeveloper

rank2 polymorphism problem with newtypes

Using this file (both with the itask and the master compiler):

module test

import StdEnv
import Data.Maybe
import Data.Functor
import Control.Applicative

class expr v where
	lit :: i -> v i | toString i
	(+.) infixl 6 :: (v i) (v i) -> v i | + i

instance expr Maybe where
	lit i = Just i
	+. x y = (+) <$> x <*> y

:: Print a = Print String
print :: (Print a) -> String
print (Print a) = a
instance expr Print where
	lit i = Print (toString i)
	+. (Print l) (Print r) = Print (l +++ "+" +++ r)

printEval :: (A.v: v a | expr v) -> (Maybe a, String)
printEval f = (f, let (Print p) = f in p)

Start :: (Maybe Int, String)
Start = printEval (lit 4 +. lit 38)

This works fine and gives the output:

((Just 42),"4+38")

However, if we change

:: Print a = Print a

to

:: Print a =: Print a

The output is wrong, and when we use the second element it obviously crashes:

((Just 42),_f54;54.12)

If we change

printEval f = (f, let (Print p) = f in p)

to

printEval f = (f, print f)

It works again.

The construction let (Print p) = f in p works fine in a non rank2 polymorphic function

To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Assignee
Assign to
None
Milestone
None
Assign milestone
Time tracking
None
Due date
None
Reference: clean-compiler-and-rts/compiler#61