Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Haskell Exercise deconstructing record syntax

Tags:

haskell

record

Starting Exercise to brush up on learned Haskell skills.

module Clock (addDelta, fromHourMin, clockDecons) where

data Clock = Clock { hours :: Int 
                   , mins  :: Int 
                   } deriving Show 

fromHourMin :: Int -> Int -> Clock
fromHourMin hour min = Clock {hours = hour, mins = min}

-- toString :: Clock -> String
clockDecons clock = (hs,ms) 
  where hs = hours 
        ms = mins

addDelta :: Int -> Int -> Clock -> Clock
addDelta hour min clock = undefined

Maybe a bit clouded after a complete day, but why do I get:

<interactive>:15:1: error:
    • No instance for (Show (Clock -> Int))
        arising from a use of ‘print’
        (maybe you haven't applied a function to enough arguments?)
    • In a stmt of an interactive GHCi command: print it

I haven't even begun to create string instances of the clock.

like image 562
Madderote Avatar asked Sep 02 '26 22:09

Madderote


1 Answers

You probably meant

clockDecons :: Clock -> (Int, Int)
clockDecons clock = (hours clock, mins clock) 
like image 147
Will Ness Avatar answered Sep 05 '26 16:09

Will Ness



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!