u/SleepyGuyy

My Newbie Error "Could not deduce ‘RealFrac a’ arising from a use of ‘floor’ from the context: Num a"

Hi, I'm learning Haskell, and I admit I'm just playing with it right now.

While I'm not a terribly experienced programmer, I do have a Bachelor's in Computer Science. My professional experience has been restricted to mostly web development in Typescript sadly.

I have not touched functional programming, but this seems unrelated to functional intricacies and more me having a primitive understanding of number types.

I'm playing with pattern matching and guards so maybe excuse the silly code, I'm just starting.
I try loading (":l haskell_test.hs") my file in GHCi and get the following compile error

"Could not deduce ‘RealFrac a’ arising from a use of ‘floor’ from the context: Num a" . I take in type Num, and floor doesn't like that general of a type, I take it?

-- testing pattern matching and guards
isXFactorOfY :: Num a => a -> a -> Bool
isXFactorOfY 0 0 = True
isXFactorOfY 0 y = False
isXFactorOfY x 0 = False
isXFactorOfY 1 1 = True
isXFactorOfY 1 y = False
isXFactorOfY x 1 = False
isXFactorOfY x y  | x > y = False
                  | abs(x / y) > floor( abs(x)/abs(y) ) = False
                  | otherwise = True

I've tried replacing Num a with Real a, RealFrac a, and some other things I've seen. But I'm just poking blindly and don't actually understand the exact issue. I'd like some help understanding it explicitly rather than stumbling upon the compile-able code.

I see the reference for floor is here: https://hackage.haskell.org/package/ClassyPrelude-0.1/docs/Prelude-Math.html#v:floor

I guess I'm confused what it want's floor to take in, I figured any number that's an Int or Float would work. But I'm not sure how to define that the way it wants.

Again sorry for the silly code. I am quite rusty and am having a rough time getting back into .... problem solving, and reading APIs and references it seems.
Thank you in advance for any help or direction you give.

The full compile error output is as follows:

ghci> :l haskell_test.hs 
[1 of 2] Compiling Main             ( haskell_test.hs, interpreted )
haskell_test.hs:3:14: error: [GHC-39999]
    • Could not deduce ‘Eq a’ arising from the literal ‘0’
      from the context: Num a
        bound by the type signature for:
                   isXFactorOfY :: forall a. Num a => a -> a -> Bool
        at haskell_test.hs:2:1-39
      Possible fix:
        add (Eq a) to the context of
          the type signature for:
            isXFactorOfY :: forall a. Num a => a -> a -> Bool
    • In the pattern: 0
      In an equation for ‘isXFactorOfY’: isXFactorOfY 0 0 = True
  |
3 | isXFactorOfY 0 0 = True
  |              ^

haskell_test.hs:9:29: error: [GHC-39999]
    • Could not deduce ‘Ord a’ arising from a use of ‘>’
      from the context: Num a
        bound by the type signature for:
                   isXFactorOfY :: forall a. Num a => a -> a -> Bool
        at haskell_test.hs:2:1-39
      Possible fix:
        add (Ord a) to the context of
          the type signature for:
            isXFactorOfY :: forall a. Num a => a -> a -> Bool
    • In the expression: x > y
      In a stmt of a pattern guard for
                     an equation for ‘isXFactorOfY’:
        x > y
      In an equation for ‘isXFactorOfY’:
          isXFactorOfY x y
            | x > y = False
            | abs (x / y) > floor (abs (x) / abs (y)) = False
            | otherwise = True
  |
9 | isXFactorOfY x y        | x > y = False
  |                             ^

haskell_test.hs:10:33: error: [GHC-39999]
    • Could not deduce ‘Fractional a’ arising from a use of ‘/’
      from the context: Num a
        bound by the type signature for:
                   isXFactorOfY :: forall a. Num a => a -> a -> Bool
        at haskell_test.hs:2:1-39
      Possible fix:
        add (Fractional a) to the context of
          the type signature for:
            isXFactorOfY :: forall a. Num a => a -> a -> Bool
    • In the first argument of ‘abs’, namely ‘(x / y)’
      In the first argument of ‘(>)’, namely ‘abs (x / y)’
      In the expression: abs (x / y) > floor (abs (x) / abs (y))
   |
10 |                         | abs(x / y) > floor( abs(x)/abs(y) ) = False
   |                                 ^

haskell_test.hs:10:40: error: [GHC-39999]
    • Could not deduce ‘RealFrac a’ arising from a use of ‘floor’
      from the context: Num a
        bound by the type signature for:
                   isXFactorOfY :: forall a. Num a => a -> a -> Bool
        at haskell_test.hs:2:1-39
      Possible fix:
        add (RealFrac a) to the context of
          the type signature for:
            isXFactorOfY :: forall a. Num a => a -> a -> Bool
    • In the second argument of ‘(>)’, namely
        ‘floor (abs (x) / abs (y))’
      In the expression: abs (x / y) > floor (abs (x) / abs (y))
      In a stmt of a pattern guard for
                     an equation for ‘isXFactorOfY’:
        abs (x / y) > floor (abs (x) / abs (y))
   |
10 |                         | abs(x / y) > floor( abs(x)/abs(y) ) = False
   |                                        ^^^^^

Failed, unloaded all modules.
reddit.com
u/SleepyGuyy — 1 day ago
▲ 4 r/Gentoo

I've been messing around a lot trying to get my system in a nice working state. I'm also learning Sway.

Last night I got lots of things working, in particular I got Discord installed and was able to call, be heard, and hear audio.

I was not able to stream in discord, so I ran some xdg_desktop_portal package installs. No issues last night.

I also ran a system update

emerge -avuDU @ world

And also had no issues.

While installing things like Discord, Vivaldi, and packages Vivaldi needed like ffmpeg, I had to use autounmask to get the packages past my liscense agreement mask.

emerge packagename --autounmask-write --autounmask

and merge using dispatch-conf, and pressing u (I checked the diff it showed, they always seemed correct, didnt cut stuff out).

At some point the next day, I noticed nano was no longer installed. I had to reinstall nano.

And later I realized I had no audio at all.

When I check /usr/bin I still have "gentoo-pipewire-launcher" available there. I'm not clear if maybe I lost some important packages or not, I wouldnt know what I installed last night.

Following a post I saw online, I had previously gotten audio working by adding

"exec /usr/bin/gentoo-pipewire-launcher &" to the top of my sway config ~/.config/sway/config.

Now that isn't working. Discord only lists "System Default" as an input and output option. Before it listed my audio devices.

I've only added a libinput rule to the end of my sway config that points to my mouse to reduce mouse speed, so it couldnt be related to that change.

Not sure how to proceed

sorry for the rambling

*UPDATE*

Running "gentoo-pipewire-launcher" returns "Pipewire already running, exiting" etc...

Also Youtube is givin "Audio renderer error".

I tried running "gentoo-pipewire-launcher restart" and it hung after Pipewire terminated.

I then Ctrl + c to close it, and ran "gentoo-pipewire-launcher" myself, which did get Youtube's audio working, but took up a terminal permanently. The terminal output was just stuck with the cursor on a newline and nothing printing out after the command. Discord noises audio started working, but not call audio (neither input nor output, no additional input/output devices were listed in Discord).

reddit.com
u/SleepyGuyy — 8 days ago
▲ 12 r/Gentoo

Over a month ago I installed Gentoo for the first time. I installed it as a dual-boot alongside a more traditional Linux OS. But for the past several weeks I have been avoiding it completely.

The reason I wanted to try Gentoo was to learn more about the mechanics and structure of a Linux system, and desktop. I also wanted to break free from my systemd dependence, and learn how to stand without it. I have used many Linux distros over the years because I find it fun to try them out, but I've never actually dipped into system admin or how services or the file system works. I don't want to dive in super far, just get a bit more than I have using Ubuntu, Zorin, Endeavor, etc... I've used Arch but I used archinstall.

I still wanted an easier distro installed on the system, to use for more day-to-day things and fall back on when I have issues in Gentoo.

Gentoo seems to have a really supportive community, and really nice documentation / guides to read through. So it's great for learning.

I spent several days installing it, reading lots of the guide, etc. It was an overall great time.
I even decided to try ZFS storage, and that went mostly well. Except I accidentally nuked one of my external drives (I know I should've unplugged it), don't know how but during the install I wiped every file off of it while preserving the partitions somehow. That was really stressful, I spent a week in the other Linux OS trying to recover files off of it. That wasn't Gentoo's fault but it soured my enthusiasm and drained my energy at the time.

After that week I got back into Gentoo and tried installing a desktop environment. I wanted a minimal desktop, that would get me to learn more about desktop setups and programs I take for granted (ex: volume control, system settings, etc). But I didn't want it to be too hard, so I went with Sway (just seemed more polished than other options, easier to get started).

I currently have a functioning login screen that starts with the system, and it logs into a Sway desktop. But I have nothing else working. Sway always had an error-red banner in the top of my second monitor saying "There are errors in your config file", which I checked the Sway config and it seems like it's the default setup. I don't have an of the conveniences yet, like a system tray / bar, or a fully functional app search (sway comes with one but it seems to miss some apps I add).

Now it's been weeks, so I completely forget how to install or update with emerge, or how to unmask things. It's all just really stressful when I start thinking about it and about how much I need to do to get a nice desktop. I considered deleting the existing login/desktop setup to start from a fresh install, maybe try Hyprland because people share configs for that a lot online? However I don't remember all the config changes I've made or things I've unmasked, or how I unmasked them, and I don't know how to uninstall all the stuff I added for Sway, or remove the sway-specific services I might've added. And I can't remember the Sway keyboard shortcuts so every time I log into Gentoo I'm stuck looking at a black desktop. And I can't set my desktop background so I can't put a cheatsheet on there.

I feel like I bit off too much, but also I really don't want to start over and do that installation again.

I just kinda wanted to vent where I'm at. I don't plan on switching off Gentoo. It's my second OS so I can just continue using my other one. But I don't want to be stuck in that OS either.

reddit.com
u/SleepyGuyy — 14 days ago