Skip to content

Commit ff17f10

Browse files
authored
Support unit () (#52)
* Add litWithSpan function * Desugar unit () * Add example of returning unit
1 parent effe6b7 commit ff17f10

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

examples/08-tuples.hell

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,5 @@ main = do
55

66
let (foo,bar) = (123, "foo")
77
Text.putStrLn bar
8+
9+
Monad.return ()

src/Hell.hs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,10 @@ data Forall where
327327
Final :: (forall g. Typed (Term g)) -> Forall
328328

329329
lit :: Type.Typeable a => a -> UTerm ()
330-
lit l = UForall HSE.noSrcSpan () [] (Final (Typed (Type.typeOf l) (Lit l))) [] (fromSomeStarType (SomeStarType (Type.typeOf l))) []
330+
lit = litWithSpan HSE.noSrcSpan
331+
332+
litWithSpan :: Type.Typeable a => HSE.SrcSpanInfo -> a -> UTerm ()
333+
litWithSpan srcSpanInfo l = UForall srcSpanInfo () [] (Final (Typed (Type.typeOf l) (Lit l))) [] (fromSomeStarType (SomeStarType (Type.typeOf l))) []
331334

332335
data SomeStarType = forall (a :: Type). SomeStarType (TypeRep a)
333336
deriving instance Show SomeStarType
@@ -610,7 +613,9 @@ desugarPolyQName qname treps =
610613
HSE.UnQual l (HSE.Symbol _ string)
611614
| Just (forall', vars, irep, _) <- Map.lookup string polyLits -> do
612615
pure (UForall l () treps forall' vars irep [])
613-
_ -> Left $ InvalidVariable $ HSE.prettyPrint qname
616+
HSE.Special l (HSE.UnitCon{}) ->
617+
pure $ litWithSpan l ()
618+
_ -> Left $ InvalidVariable $ show qname
614619

615620
desugarArg :: HSE.Pat HSE.SrcSpanInfo -> Either DesugarError (Binding, Maybe SomeStarType)
616621
desugarArg (HSE.PatTypeSig _ (HSE.PVar _ (HSE.Ident _ i)) typ) =

0 commit comments

Comments
 (0)