haskell,compiler-errors,instance,equality,typeclass , Haskell: `==' is not a (visible) method of class


Haskell: `==' is not a (visible) method of class

Question:

Tag: haskell,compiler-errors,instance,equality,typeclass

So, when I compile the following piece of code edited:

 instance (Eq a) => PartOrd a where 
   [] == []         = True
   (x:xs) == (y:ys) = x==y && xs==ys
    _==_             = False
    xs /= ys         = not (xs == ys)

I get:

  `==' is not a (visible) method of class 'PartOrd'

  `/=' is not a (visible) method of class 'PartOrd'
Failed, modules loaded: none.

I have looked at How to properly instantiate classes in Haskell? for some clarifications but even though I wasn`t able to fix it.

Also, is it the same when I use custom-made operators such as =~ for == and '/~' for /=, because I get the same error?

EDIT: As requested:

class Eq a => PartOrd a where

   partcmp :: a -> a -> Maybe Ordering 
   partcmp x y = case bigger x y of
                   True   -> Just LT
                   False  -> case smaller x y of
                               True  -> Just GT
                               False -> case x == y of
                                          True  -> Just EQ
                                          False -> Nothing      

Answer:

It isn't clear what you are trying to achieve. Here are some thoughts:

  1. When you declare an instance of a class like instance (Eq a) => PartOrd a, you are expected to provide implementations for the functions in PartOrd a (ie partcmp, not == and \=). The compiler is telling you exactly that: == and \= are in the class Eq, not PartOrd, and you have no business defining functions not in PartOrd. In fact, no matter whether you use ==, or =~ or \~, the problem persists: you shouldn't be defining anything other that partcmp in instance (Eq a) => PartOrd a. The (Eq a) => part just says that in these definitions you can assume functions == and \= of type signatures (==), (\=) :: a -> a -> a have been defined.

  2. Why are you using lists in the instance declaration? Did you maybe mean to say instance (Eq a) => PartOrd [a]? If you really meant to say instance (Eq a) => PartOrd a, you will need to turn on the FlexibleInstances (and maybe something more too...) in GHC. (However, it doesn't really make sense to have instance (Eq a) => PartOrd a.)

  3. Finally, where do the function bigger and smaller come from? You can't use them in class (Eq a) => PartOrd a, since a is a general type. You would need functions bigger, smaller :: a -> a -> a, in which case you wouldn't even really need the PartOrd class.


Related:


How does Frege generalize number literals?


haskell,frege
It appears that Frege can evaluate 1/2 to return the Double value 0.5. The literal 1 is of type Int. It seems to be promoted to Double, which is a type in the Real class and thus knows the / operator. How does this happen? Is it using the Haskell...

Idiomatic list construction


list,haskell,functional-programming,idiomatic
I'm very new to Haskell and functional programming in general, so I don't really know how to make this code idiomatic: type Coord = Double data Point = Point Coord Coord Coord deriving Show type Polyline = [Point] -- Add a point to a polyline addPoint :: Polyline -> Point...

Haskell make recipe fails for Paradox theorem prover using GHC


linux,haskell,make,ghc,theorem-proving
I am trying to install the paradox theorem prover sourced from here. When I run the makefile this is the command that runs: ghc -optl -static -lstdc++ -I../instantiate -I../minisat/current-base ../minisat/current-base/Solver.or ../minisat/current-base/Prop.or ../instantiate/MiniSatWrapper.or ../instantiate/MiniSatInstantiateClause.or -fglasgow-exts -O2 -static -threaded -main-is Paradox.Main.main --make Paradox.Main -o paradox And it results in several errors like...

Replace all [ ] with {} - as short as possible [on hold]


haskell
Given the code below: import Data.List; main = (readLn :: IO [Integer]) >>= print . subsequences It takes a list of integers from standard input (for example [1,2,3]) and outputs something like: [[],[1],[2],[1,2],[3],[1,3],[2,3],[1,2,3]] I want it to be like this: {},{1},{2},{1,2},{3},{1,3},{2,3},{1,2,3}} so my goal is to replace every [ and...

Why is f <$> g <$> x equivalent to (f . g) <$> x although <$> is not right-associative?


haskell,syntax,infix-notation,applicative,infix-operator
Why is f <$> g <$> x equivalent to (f . g) <$> x although <$> is not right-associative? (This kind of equivalence is valid in a popular idiom with plain $, but currently $ is right-associative!) <*> has the same associativity and precedence as <$>, but behaves differently! Example:...

How to throw an error in the LESS compiler


css,compiler-errors,less,throw,less-mixins
Question Is there any way to (programmatically) throw an error in the LESS compiler? Why? I have been fiddling around with mixin guards today, because I wanted to generate my CSS margin based upon element size and element count. I thought it would be cool to directly throw an error...

Fold over a heterogeneous, compile time, list


haskell,type-level-computation,hlist
I have a list of heterogeneous types (or at least that's what I have in mind): data Nul data Bits b otherBits where BitsLst :: b -> otherBits -> Bits b otherBits NoMoreBits :: Bits b Nul Now, given an input type b, I want to go through all the...

App crashing after pushing button, but the action is working


android,button,android-studio,compiler-errors
Maybe someone sees an error, the problem is that when i push btn2 (button 2) and btn3 (button 3) app crashes, but action still works, i.e video is running and PDF opens, while button 1 is working correctly... @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); configureImageButton(); mCamera = getCameraInstance();...

Float comparision in C [duplicate]


c,if-statement,compiler-errors,floating-point,floating-point-precision
This question already has an answer here: How dangerous is it to compare floating point values? 8 answers #include<stdio.h> int main() { float x = 0.6; if (x == 0.6) printf("IF"); else if (x == 0.6f) printf("ELSE IF"); else printf("ELSE"); } This code gives output ELSE IF #include<stdio.h> int...

Haskell IO - read from standard input directly to list


haskell
Haskell IO system is super hard to understand for me so i have question : How to read from standard input to list ? I know that there is function getLine :: IO String and interact. But i do not know how to convert the input to list so I...

Why doesn't `iterate` from the Prelude tie the knot?


haskell,tying-the-knot
Why isn't iterate defined like iterate :: (a -> a) -> a -> [a] iterate f x = xs where xs = x : map f xs in the Prelude?...

Setting id and class with the haskell diagrams package


haskell,svg,haskell-diagrams
I am working with the diagrams package for haskell, and I am using the SVG backend. I embed the SVG markup directly into an HTML document, so that the graph as a part of a web page. I have built a pretty cool looking bar graph, and I would like...

Refactor an IO recursive loop into a monad folding in Haskell


sockets,haskell,network-programming,io-monad
I writing a tcp server, and here's my main loop method: serverLoop :: Socket -> IO () serverLoop sock = do (conn, _) <- accept sock forkIO $ handleConn conn serverLoop sock (Note: handleConn :: Socket -> IO () is a function specific to my program.) I would like to...

Access to reference in member variable discards constness


c++,c++11,reference,compiler-errors,const
I made a wrapper around an object in my code that should modify accesses to the object. I choose to use an object here for testing instead of a functor that would have the same functionality. Basically: The wrapper receives a reference to the object and forwards all indexed accesses...

How to convert a Rational into a “pretty” String?


haskell,formatting,rational
I want to display some Rational values in their decimal expansion. That is, instead of displaying 3 % 4, I would rather display 0.75. I'd like this function to be of type Int -> Rational -> String. The first Int is to specify the maximum number of decimal places, since...

Get each fibbonacci value in haskell


haskell,fibonacci
I'm learning haskell and I have the following code: fib a b = a : fib b (a + b) findFibSum = sum [x | x <- fib 1 2, mod x 2 == 0 && x < 100] If I run findFibSum nothing happens, it just sits there. Shouldn't...

How do I avoid writing this type of Haskell boilerplate code


haskell,boilerplate
I run into this situation often enough for it to be annoying. Let's say I have a sum type which can hold an instance of x or a bunch of other things unrelated to x - data Foo x = X x | Y Int | Z String | ...(other...

Keep track of loop without a counter


haskell
Say, I got a list which length can be odd or even. Every iteration , I remove two items from the list. If there is one or no item at the end, I end the execution. If I store (length list)/2 every loop, I will get e.g. [5,4,3...] for a...

Fortran compiler for mac to read program


compiler-errors,fortran,fortran77,g77
I'm using the g77 compiler (on terminal I just type g77 filename.for ) on a Mac. It can't read my fortran program and I can't modify the program (very old program, not mine, and I really just need the output from it). Any suggestion for another compiler to read the...

Running executable files using Haskell


shell,haskell,command-line-arguments,executable
Say there's a C++ code that I've compiled into an executable using: g++ test.cpp -o testcpp I can run this using Terminal (I'm using OS X), and provide an input file for processing inside the C++ program, like: ./testcpp < input.txt I was wondering if doing this is possible, from...

Haskell do clause with multiple monad types


haskell,monads
I'm using a graphic library in Haskell called ThreePennyUI. In this library the main function returns a UI monad object. This causes me much headache as when I attempt to unpack IO values into local variables I receive errors complaining of different monad types. Here's an example of my problem:...

Why is lazy evaluation in Haskell “not being lazy”?


haskell,lazy-evaluation
When I tried the following code in cghi: take 1 $ take 1 $ repeat [1..] I was expecting the result of 1 instead of [[1,2,3,4,5,6,7,8,9,10,... printing on my terminal. Why is lazy evaluation not functioning as I'm hoping under such situation?...

What is haskellng? What is the difference between 'haskellPackages' and 'haskellngPackages'?


haskell,cabal,cabal-install,nix,haskell-ng
I have been reading this StackOverflow post in which we are advised to use the haskellng package set. I have also read this but I did not understand what haskellng is. I have read this too, but I still don't know what haskellng is. Could someone please explain what haskellng...

issues with installing newer cabal version for haskell vim now


ubuntu,haskell,vim,ubuntu-14.04,cabal
I would like to install this vim plugin: https://github.com/begriffs/haskell-vim-now When trying to run the suggested installation script: curl -o - https://raw.githubusercontent.com/begriffs/haskell-vim-now/master/install.sh | bash I get: --- Cabal version 1.18 or later is required. Aborting. I then try to install a newer version of cabal: [email protected]:~/Downloads/cabal-install-1.22.6.0$ ./bootstrap.sh The response I get:...

Haskell: When declaring a class, how can I use a type variable that is not immediately in the constructors?


haskell
I want to define a function, <-? to check whether an element is in a list/set/map. module Test where import qualified Data.Map as Map import qualified Data.Set as Set class Memberable a where (<-?) :: b -> a -> Bool instance Memberable [x] where (<-?) = elem instance Memberable (Map.Map...

When will travis-ci support ghc 7.10?


haskell,travis-ci
I'd like to use travis-ci on my Haskell projects, but they require the latest version of GHC.

Haskell return lazy string from file IO


haskell,file-io,lazy-evaluation
Here I'm back again with a (for me) really strange behaviour of my newest masterpiece... This code should read a file, but it doesn't: readCsvContents :: String -> IO ( String ) readCsvContents fileName = do withFile fileName ReadMode (\handle -> do contents <- hGetContents handle return contents ) main...

Decremented value called in the recursion in Haskell


string,function,haskell,recursion,parameters
So, I have this function that aligns the text to the left for a given column width. I have already fixed some of its problems, but I am unable to make it not use the decremented parameter once it is called, but to return to the starting value of n....

Implementing map on a tree using fold


scala,haskell
I am trying to implement a map using fold. I could do so in Haskell data Tree a = EmptyTree | Node a (Tree a) (Tree a) deriving (Show) foldTree :: Tree a -> b -> (b -> a -> b -> b) -> b foldTree EmptyTree d _ =...

How can I express foldr in terms of foldMap for type-aligned sequences?


haskell,types,monoids,type-variables,foldable
I'm playing around with type-aligned sequences, and in particular I'm messing around with the idea of folding them. A foldable type-aligned sequence looks something like this: class FoldableTA fm where foldMapTA :: Category h => (forall b c . a b c -> h b c) -> fm a b...

Recursion scheme in Haskell for repeatedly breaking datatypes into “head” and “tail” and yielding a structure of results


haskell,recursion
In Haskell, I recently found the following function useful: listCase :: (a -> [a] -> b) -> [a] -> [b] listCase f [] = [] listCase f (x:xs) = f x xs : listCase f xs I used it to generate sliding windows of size 3 from a list, like...

Multiple definition and file management


c,arrays,compilation,compiler-errors,include
I'm writing a program for vocabulary training, for myself. And the program itself should be available in different languages, atm in German and English. What I want is to have a Main File which manage all and two separate files for the functions in the right language. I compile all...

First three items of a list in Haskell


haskell
I am very new to Haskell, and struggling a bit with a function here. The premise is simple enough: Run through a list, and combine each 3 items next to each other with another function and return a list with the results. The problem is to do it in a...

Hook into GHC runtime system


haskell,functional-programming,runtime,transactional-memory
I have been looking at how transactional memory is implemented in Haskell, and I am not sure I understand how the STM operations exposed to the programmer hook into the runtime system functions written in C. In ghc/libraries/base/GHC/Conc/Sync.hs of the git repo, I see the following definitions: -- |A monad...

setting objects equal to eachother (java)


java,methods,compiler-errors,equals
So I have a class called Person which looks like this public class Person { private String personName; public String toString(){ return personName; } public Person(String personName){ this.personName = personName; } } and another class in which I am creating the object(s) person public class IdanJavaTask { public static void...

logical expression evaluator Haskell


haskell
I wrote the following logical expression evaluator. It works for simple 2-member expressions, and it runs but produces a fault for expression containing other expressions as the second/first member. Here's my code. data Expression = Literal Bool | Operation Operator Expression Expression data Operator = AND | OR eval ::...

IO Monad Example


haskell
Consider the following IO code: ghci> let x = return 100 :: IO Int ghci> :t do { a <- x; print a; return 500 } do { a <- x; print a; return 500 } :: Num b => IO b My understanding of do notation/bind is that the...

Mapping with IO actions in Haskell


list,haskell,io
I have a function that takes two filenames, and reads the contents of those two files into Strings, and then returns if they match or not. Here's the function: f :: String -> String -> IO Bool f fileName1 fileName2 = do str1 <- readFile fileName1 str2 <- readFile fileName2...

Haskell powerset function - How to avoid Couldn't match expected type `IO t0' with actual type `[[Integer]]'


haskell
I have a powerset implementation that I'm trying to run here: http://rextester.com/runcode. I'm still getting this error and can't figure out how to make it right. I'm trying to read as much as possible about IO in haskell but it is super hard for me. import Control.Monad (filterM) powerset =...

Best practice for handling data types from 3rd party libraries in Haskell?


haskell,types
I'm just getting into my first real Haskell project of size (a web app), and I'm starting to run into issues with types from 3rd party libraries leaking all over my code. Here is a quick example: My Parser module imports Test.Parsec, and the exports a function (parseConfig) that returns...

Tokenizer identifier in Haskell


haskell
I'm writing this small program basically to identify each input tokens as operator/parenthesis/int. However, I encountered a problem stating that Not in scope: data constructor `Integer' Here's what I have so far (Data.Char only defines isDigit, nothing else) import Data.Char (isDigit) data Token = TPlus | TTimes | TParenLeft |...

apply a transformation with function inline


haskell
Starting from a simple case of "fold" (I used (+) but can be anything else): Prelude.foldl (+) 0 [10,20,30] is it possible apply an inline transformation similar to (that doesn't work): Prelude.foldl ((+) . (\x -> read x :: Int)) 0 ["10","20","30"] In case not, is there an alternative to...

Can't reference a variable from App.config


c#,compiler-errors,app-config
I'm trying to reference a variable from App.config in my C# file. Here's a sample of my code. App.config: <appSettings> <add key="ErrorEmails" value="[email protected]"/> </appSettings> Code: SettingsIO setIO = new SettingsIO(); public static string To = setIO.ReadSetting("ErrorEmails"); The error reads: A field initializer cannot reference the non-static field, method, or preperty...

Dereferencing pointer to incomplete type error for struct member access in Python swig C wrapper


python,c,gcc,compiler-errors,swig
What is the error while compiling swig Python wrapper under GCC 4.8.2? wfdb_python_wrap.c:3967:11: error: dereferencing pointer to incomplete type if (arg1->fname) free((char*)arg1->fname); ^ wfdb_python_wrap.c:3967:36: error: dereferencing pointer to incomplete type if (arg1->fname) free((char*)arg1->fname); source code from wfdb_python_wrap.c: ... #include <wfdb/wfdb.h> ... #ifdef __cplusplus extern "C" { #endif SWIGINTERN PyObject *_wrap_WFDB_Siginfo_fname_set(PyObject...

How to “wrap” monadic return value


haskell,monads
I have the following code: data APNSIdentifier = NoIdentifier | Identifier Word32 deriving (Show, Eq) newtype APNSItem = Item Put createNotificationIdentifierItem :: APNSIdentifier -> APNSItem <--- here createNotificationIdentifierItem (Identifier identifier) = do putWord8 3 putWord16be 4 putWord32be identifier How can I "wrap" the Put monad with an APNSItem? Do I...

Combining Event and an attribute in threepenny-gui


haskell,threepenny-gui
I have an Event String which I want to sink into a textarea. This works fine, but now I want to combine the current value of a checkbox selection to this string. First I did this by using checkedChange of the checkbox which works, but has a problem. If the...

Haskell - generate and use the same random list


haskell,random
In Haskell, I'd like to generate a random list of Ints and use it throughout my program. My current solution causes the array to be created randomly each time I access/use it. How can I overcome this problem?...

Thread blocked indefinitely in an MVar operation


haskell,concurrency,network-programming
I have been attempting to debug a problem when using multiple MVars, however to no luck. My code uses two MVars: one to store the servers current state, and another to pass network events to and from the client threads. However after connecting and disconnecting several times, the server stops...

Call to implicitly-deleted copy constructor in LLVM(Porting code from windows to mac)


c++,osx,c++11,compiler-errors,llvm
We are in the process of porting some c++ code from windows to mac and are having issues compiling it with LLVM 6.1 using c++11. We are encountering errors all over the place of "Call to implicitly-deleted copy contructor" Some of these errors are popping up in our code. for...

Stopping condition on a recursive function - Haskell


string,function,haskell,if-statement,recursion
So, I have this function which aims to align the text on the left without cutting words(only white spaces). However my problem is that I cannot find a stopping condition of the function and it goes infinitely. f n "" = "" --weak condition f n s = if n...