Skip to main content
added 352 characters in body
Source Link
Laikoni
  • 26.3k
  • 6
  • 52
  • 115

Haskell + Data.Dates, 88 81 74 69 6655 bytes

import Data.Dates
main=pure$!succ.dateWeekDay<$>getCurrentDateTime

Try it online!

This uses the fact that Sunday is the last day of the week. dateWeekDay returns the day of the week as a WeekDay type, which is simply defined as

data WeekDay = Monday | Tuesday | Wednesday | Thursday | Friday | Saturday | Sunday

WeekDay is an instance of Enum, thus we can use succ and pred to get the successor or predecessor of a weekday, e.g. succ Monday yields Tuesday.

However, Sunday is the last enum entry, so calling succ Sunday results in the following error:

fail_on_sunday.hs: succ{WeekDay}: tried to take `succ' of last tag in enumeration
CallStack (from HasCallStack):
  error, called at .\Data\Dates.hs:56:34 in dates-0.2.2.1-6YwCvjmBci55IfacFLnAPe:Data.Dates

Edit 1: Thanks to nimi for -3 bytes!
Edit 2: -11 bytes now that functions are allowed.


Full program: 88 81 74 69 66 bytes

import Data.Dates
main=pure$!succ.dateWeekDay<$>getCurrentDateTime

Try it online!

pure is needed to lift the resulting WeekDay back into the IO Monad. However, Haskell sees that the value is not output in any way by the program, so lazy as it is, the expression is not evaluated, so even on Sundays the program would not fail. This is why $! is needed, which forces the evaluation even if Haskell would normally not evaluate the expression.

Edit: Thanks to nimi for -3 bytes!


Haskell, 127 124 bytes

Previous approach with Data.Time: 127 124 bytes

import Data.Time.Clock
import Data.Time.Calendar.WeekDate
c(_,_,d)|d<7=d
main=getCurrentTime>>=(pure$!).c.toWeekDate.utctDay

Try it online! These are some impressive imports. Change d<7 to e.g. d/=5 to test failure on a Friday. Fails with the following exception: Non-exhaustive patterns in function c.

Haskell + Data.Dates, 88 81 74 69 66 bytes

import Data.Dates
main=pure$!succ.dateWeekDay<$>getCurrentDateTime

Try it online!

This uses the fact that Sunday is the last day of the week. dateWeekDay returns the day of the week as a WeekDay type, which is simply defined as

data WeekDay = Monday | Tuesday | Wednesday | Thursday | Friday | Saturday | Sunday

WeekDay is an instance of Enum, thus we can use succ and pred to get the successor or predecessor of a weekday, e.g. succ Monday yields Tuesday.

However, Sunday is the last enum entry, so calling succ Sunday results in the following error:

fail_on_sunday.hs: succ{WeekDay}: tried to take `succ' of last tag in enumeration
CallStack (from HasCallStack):
  error, called at .\Data\Dates.hs:56:34 in dates-0.2.2.1-6YwCvjmBci55IfacFLnAPe:Data.Dates

pure is needed to lift the resulting WeekDay back into the IO Monad. However, Haskell sees that the value is not output in any way by the program, so lazy as it is, the expression is not evaluated, so even on Sundays the program would not fail. This is why $! is needed, which forces the evaluation even if Haskell would normally not evaluate the expression.

Edit: Thanks to nimi for -3 bytes!


Haskell, 127 124 bytes

import Data.Time.Clock
import Data.Time.Calendar.WeekDate
c(_,_,d)|d<7=d
main=getCurrentTime>>=(pure$!).c.toWeekDate.utctDay

Try it online! These are some impressive imports. Change d<7 to e.g. d/=5 to test failure on a Friday. Fails with the following exception: Non-exhaustive patterns in function c.

Haskell + Data.Dates, 55 bytes

import Data.Dates
succ.dateWeekDay<$>getCurrentDateTime

Try it online!

This uses the fact that Sunday is the last day of the week. dateWeekDay returns the day of the week as a WeekDay type, which is simply defined as

data WeekDay = Monday | Tuesday | Wednesday | Thursday | Friday | Saturday | Sunday

WeekDay is an instance of Enum, thus we can use succ and pred to get the successor or predecessor of a weekday, e.g. succ Monday yields Tuesday.

However, Sunday is the last enum entry, so calling succ Sunday results in the following error:

fail_on_sunday.hs: succ{WeekDay}: tried to take `succ' of last tag in enumeration
CallStack (from HasCallStack):
  error, called at .\Data\Dates.hs:56:34 in dates-0.2.2.1-6YwCvjmBci55IfacFLnAPe:Data.Dates

Edit 1: Thanks to nimi for -3 bytes!
Edit 2: -11 bytes now that functions are allowed.


Full program: 88 81 74 69 66 bytes

import Data.Dates
main=pure$!succ.dateWeekDay<$>getCurrentDateTime

Try it online!

pure is needed to lift the resulting WeekDay back into the IO Monad. However, Haskell sees that the value is not output in any way by the program, so lazy as it is, the expression is not evaluated, so even on Sundays the program would not fail. This is why $! is needed, which forces the evaluation even if Haskell would normally not evaluate the expression.


Previous approach with Data.Time: 127 124 bytes

import Data.Time.Clock
import Data.Time.Calendar.WeekDate
c(_,_,d)|d<7=d
main=getCurrentTime>>=(pure$!).c.toWeekDate.utctDay

Try it online! These are some impressive imports. Change d<7 to e.g. d/=5 to test failure on a Friday. Fails with the following exception: Non-exhaustive patterns in function c.

added 133 characters in body
Source Link
Laikoni
  • 26.3k
  • 6
  • 52
  • 115

Haskell + Data.Dates, 88 81 74 6969 66 bytes

import Data.Dates
main=getCurrentDateTime>>=(pure$main=pure$!).succ.dateWeekDaydateWeekDay<$>getCurrentDateTime

(Currently not working on TIO because the dates package is missing.)Try it online!

This uses the fact that Sunday is the last day of the week. dateWeekDay returns the day of the week as a WeekDay type, which is simply defined as

data WeekDay = Monday | Tuesday | Wednesday | Thursday | Friday | Saturday | Sunday

WeekDay is an instance of Enum, thus we can use succ and pred to get the successor or predecessor of a weekday, e.g. succ Monday yields Tuesday.

However, Sunday is the last enum entry, so calling succ Sunday results in the following error:

fail_on_sunday.hs: succ{WeekDay}: tried to take `succ' of last tag in enumeration
CallStack (from HasCallStack):
  error, called at .\Data\Dates.hs:56:34 in dates-0.2.2.1-6YwCvjmBci55IfacFLnAPe:Data.Dates

pure is needed to lift the resulting WeekDay back into the IO Monad. However, Haskell sees that the value is not output in any way by the program, so lazy as it is, the expression is not evaluated, so even on Sundays the program would not fail. This is why $! is needed, which forces the evaluation even if Haskell would normally not evaluate the expression.

Edit: Thanks to nimi for -3 bytes!


Haskell, 127 124 bytes

import Data.Time.Clock
import Data.Time.Calendar.WeekDate
c(_,_,d)|d<7=d
main=getCurrentTime>>=(pure$!).c.toWeekDate.utctDay

Try it online! These are some impressive imports. Change d<7 to e.g. d/=5 to test failure on a Friday. Fails with the following exception: Non-exhaustive patterns in function c.

Haskell + Data.Dates, 88 81 74 69 bytes

import Data.Dates
main=getCurrentDateTime>>=(pure$!).succ.dateWeekDay

(Currently not working on TIO because the dates package is missing.)

This uses the fact that Sunday is the last day of the week. dateWeekDay returns the day of the week as a WeekDay type, which is simply defined as

data WeekDay = Monday | Tuesday | Wednesday | Thursday | Friday | Saturday | Sunday

WeekDay is an instance of Enum, thus we can use succ and pred to get the successor or predecessor of a weekday, e.g. succ Monday yields Tuesday.

However, Sunday is the last enum entry, so calling succ Sunday results in the following error:

fail_on_sunday.hs: succ{WeekDay}: tried to take `succ' of last tag in enumeration
CallStack (from HasCallStack):
  error, called at .\Data\Dates.hs:56:34 in dates-0.2.2.1-6YwCvjmBci55IfacFLnAPe:Data.Dates

pure is needed to lift the resulting WeekDay back into the IO Monad. However, Haskell sees that the value is not output in any way by the program, so lazy as it is, the expression is not evaluated, so even on Sundays the program would not fail. This is why $! is needed, which forces the evaluation even if Haskell would normally not evaluate the expression.


Haskell, 127 124 bytes

import Data.Time.Clock
import Data.Time.Calendar.WeekDate
c(_,_,d)|d<7=d
main=getCurrentTime>>=(pure$!).c.toWeekDate.utctDay

Try it online! These are some impressive imports. Change d<7 to e.g. d/=5 to test failure on a Friday. Fails with the following exception: Non-exhaustive patterns in function c.

Haskell + Data.Dates, 88 81 74 69 66 bytes

import Data.Dates
main=pure$!succ.dateWeekDay<$>getCurrentDateTime

Try it online!

This uses the fact that Sunday is the last day of the week. dateWeekDay returns the day of the week as a WeekDay type, which is simply defined as

data WeekDay = Monday | Tuesday | Wednesday | Thursday | Friday | Saturday | Sunday

WeekDay is an instance of Enum, thus we can use succ and pred to get the successor or predecessor of a weekday, e.g. succ Monday yields Tuesday.

However, Sunday is the last enum entry, so calling succ Sunday results in the following error:

fail_on_sunday.hs: succ{WeekDay}: tried to take `succ' of last tag in enumeration
CallStack (from HasCallStack):
  error, called at .\Data\Dates.hs:56:34 in dates-0.2.2.1-6YwCvjmBci55IfacFLnAPe:Data.Dates

pure is needed to lift the resulting WeekDay back into the IO Monad. However, Haskell sees that the value is not output in any way by the program, so lazy as it is, the expression is not evaluated, so even on Sundays the program would not fail. This is why $! is needed, which forces the evaluation even if Haskell would normally not evaluate the expression.

Edit: Thanks to nimi for -3 bytes!


Haskell, 127 124 bytes

import Data.Time.Clock
import Data.Time.Calendar.WeekDate
c(_,_,d)|d<7=d
main=getCurrentTime>>=(pure$!).c.toWeekDate.utctDay

Try it online! These are some impressive imports. Change d<7 to e.g. d/=5 to test failure on a Friday. Fails with the following exception: Non-exhaustive patterns in function c.

added 368 characters in body
Source Link
Laikoni
  • 26.3k
  • 6
  • 52
  • 115

Haskell + Data.Dates, 88 81 7474 69 bytes

import Data.Dates
main=do t<-getCurrentDateTime;pure$main=getCurrentDateTime>>=(pure$![dateWeekDay t).succ.]!!1dateWeekDay

(Currently not working on TIO because the dates package is missing.)

This uses the fact that Sunday is the last day of the week. dateWeekDay t with the current DateTime value t returns the day of the week as a WeekDay type, which is simply defined as

data WeekDay = Monday | Tuesday | Wednesday | Thursday | Friday | Saturday | Sunday

WeekDay is an instance of Enum, thus we can use them in rage statementssucc and pred to get the successor or predecessor of a weekday, e.g. [Fridaysucc ..]Monday yields the list [Friday,Saturday,Sunday]Tuesday.

With [dateWeekDay t..]!!1 we access the second element of that listHowever, which works for all weekdays except Sunday is the last enum entry, in which case aso calling Prelude.!!: index toosucc largeSunday exception is thrown.results in the following error:

fail_on_sunday.hs: succ{WeekDay}: tried to take `succ' of last tag in enumeration
CallStack (from HasCallStack):
  error, called at .\Data\Dates.hs:56:34 in dates-0.2.2.1-6YwCvjmBci55IfacFLnAPe:Data.Dates

pure is needed to lift the resulting WeekDay back into the IO Monad. However, Haskell sees that the value is not output in any way by the program, so lazy as it is, the expression is not evaluated, so even on Sundays the program would not fail. This is why $! is needed, which forces the evaluation even if Haskell would normally not evaluate the expression.


Haskell, 127 124 bytes

import Data.Time.Clock
import Data.Time.Calendar.WeekDate
c(_,_,d)|d<7=d
main=getCurrentTime>>=(pure$!).c.toWeekDate.utctDay

Try it online! These are some impressive imports. Change d<7 to e.g. d/=5 to test failure on a Friday. Fails with the following exception: Non-exhaustive patterns in function c.

Haskell + Data.Dates, 88 81 74 bytes

import Data.Dates
main=do t<-getCurrentDateTime;pure$![dateWeekDay t..]!!1

(Currently not working on TIO because the dates package is missing.)

This uses the fact that Sunday is the last day of the week. dateWeekDay t with the current DateTime value t returns the day of the week as a WeekDay type, which is simply defined as

data WeekDay = Monday | Tuesday | Wednesday | Thursday | Friday | Saturday | Sunday

WeekDay is an instance of Enum, thus we can use them in rage statements, e.g. [Friday ..] yields the list [Friday,Saturday,Sunday].

With [dateWeekDay t..]!!1 we access the second element of that list, which works for all weekdays except Sunday, in which case a Prelude.!!: index too large exception is thrown.

pure is needed to lift the resulting WeekDay back into the IO Monad. However, Haskell sees that the value is not output in any way by the program, so lazy as it is, the expression is not evaluated, so even on Sundays the program would not fail. This is why $! is needed, which forces the evaluation even if Haskell would normally not evaluate the expression.


Haskell, 127 124 bytes

import Data.Time.Clock
import Data.Time.Calendar.WeekDate
c(_,_,d)|d<7=d
main=getCurrentTime>>=(pure$!).c.toWeekDate.utctDay

Try it online! These are some impressive imports. Change d<7 to e.g. d/=5 to test failure on a Friday. Fails with the following exception: Non-exhaustive patterns in function c.

Haskell + Data.Dates, 88 81 74 69 bytes

import Data.Dates
main=getCurrentDateTime>>=(pure$!).succ.dateWeekDay

(Currently not working on TIO because the dates package is missing.)

This uses the fact that Sunday is the last day of the week. dateWeekDay returns the day of the week as a WeekDay type, which is simply defined as

data WeekDay = Monday | Tuesday | Wednesday | Thursday | Friday | Saturday | Sunday

WeekDay is an instance of Enum, thus we can use succ and pred to get the successor or predecessor of a weekday, e.g. succ Monday yields Tuesday.

However, Sunday is the last enum entry, so calling succ Sunday results in the following error:

fail_on_sunday.hs: succ{WeekDay}: tried to take `succ' of last tag in enumeration
CallStack (from HasCallStack):
  error, called at .\Data\Dates.hs:56:34 in dates-0.2.2.1-6YwCvjmBci55IfacFLnAPe:Data.Dates

pure is needed to lift the resulting WeekDay back into the IO Monad. However, Haskell sees that the value is not output in any way by the program, so lazy as it is, the expression is not evaluated, so even on Sundays the program would not fail. This is why $! is needed, which forces the evaluation even if Haskell would normally not evaluate the expression.


Haskell, 127 124 bytes

import Data.Time.Clock
import Data.Time.Calendar.WeekDate
c(_,_,d)|d<7=d
main=getCurrentTime>>=(pure$!).c.toWeekDate.utctDay

Try it online! These are some impressive imports. Change d<7 to e.g. d/=5 to test failure on a Friday. Fails with the following exception: Non-exhaustive patterns in function c.

added 368 characters in body
Source Link
Laikoni
  • 26.3k
  • 6
  • 52
  • 115
Loading
deleted 2 characters in body
Source Link
Laikoni
  • 26.3k
  • 6
  • 52
  • 115
Loading
deleted 2 characters in body
Source Link
Laikoni
  • 26.3k
  • 6
  • 52
  • 115
Loading
added 222 characters in body
Source Link
Laikoni
  • 26.3k
  • 6
  • 52
  • 115
Loading
Source Link
Laikoni
  • 26.3k
  • 6
  • 52
  • 115
Loading