Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions examples/45-enum.hell
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
main = do
IO.print $ List.take 5 $ Enum.enumFrom 1
IO.print $ Enum.enumFromTo 1 10
IO.print $ List.take 5 $ Enum.enumFrom 'a'
IO.print $ List.take 5 $ Enum.enumFrom Bool.False
IO.print $ List.take 5 $ Enum.enumFrom (Int.toInteger 1)
IO.print $ List.take 5 $ Enum.enumFrom $
Maybe.maybe (Error.error "Bad day.") Function.id $ Day.fromGregorianValid (Int.toInteger 2020) 01 01

-- simple list generators
IO.print [1 .. 3]
IO.print $ List.take 5 ['a' ..]
19 changes: 19 additions & 0 deletions src/Hell.hs
Original file line number Diff line number Diff line change
Expand Up @@ -904,6 +904,12 @@ instances =
instance0 @Ord @Text,
instance0 @Ord @ByteString,
instance0 @Ord @ExitCode,
instance0 @Enum @Int,
instance0 @Enum @Integer,
instance0 @Enum @Day,
instance0 @Enum @DayOfWeek,
instance0 @Enum @Bool,
instance0 @Enum @Char,
instance0 @Monad @IO,
instance0 @Monad @Maybe,
instance0 @Monad @[],
Expand Down Expand Up @@ -1226,6 +1232,15 @@ desugarExp userDefinedTypeAliases globals = go mempty
squash _ = Left BadDoNotation
squash stmts >>= go scope
HSE.RecConstr _ qname fields -> go scope $ makeConstructRecord qname fields
-- generators sugars
HSE.EnumFromTo l from to -> do
let enumFromTo' = HSE.Var l (HSE.Qual l (HSE.ModuleName l "Enum") (HSE.Ident l "enumFromTo"))
go scope $
HSE.App l (HSE.App l enumFromTo' from) to
HSE.EnumFrom l from -> do
let enumFrom' = HSE.Var l (HSE.Qual l (HSE.ModuleName l "Enum") (HSE.Ident l "enumFrom"))
go scope $ HSE.App l enumFrom' from
-- end of generator sugars
e -> Left $ UnsupportedSyntax $ show e

-- | Handles both user-defined case and primitive type case (Maybe, Either, etc.)
Expand Down Expand Up @@ -2184,6 +2199,10 @@ polyLits =
"Ord.lt" (Ord.<) :: forall a. (Ord a) => a -> a -> Bool
"Ord.gt" (Ord.>) :: forall a. (Ord a) => a -> a -> Bool

-- Enum
"Enum.enumFrom" enumFrom :: forall a. Enum a => a -> [a]
"Enum.enumFromTo" enumFromTo :: forall a. Enum a => a -> a -> [a]

-- Tuples
"Tuple.(,)" (,) :: forall a b. a -> b -> (a, b)
"Tuple.(,)" (,) :: forall a b. a -> b -> (a, b)
Expand Down