class,haskell,opengl,types,uniform , Haskell - Could not deduce … from Context error - OpenGL AsUniform class type

Haskell - Could not deduce … from Context error - OpenGL AsUniform class type


Tag: class,haskell,opengl,types,uniform

I'm working on making my data types general instead of taking in the OpenGL type GLfloat. So I started making it take in type a and then just replacing everything with that.

Now, I've come to a point where I'm setting uniform variables, but they take in GLfloat's. I'm using a library called GLUtil which makes it a bit easier, which has provided a class AsUniform, to check whether the type can be a uniform variable or not. I stick it in my type signature, but it stills gives me an error. Here's the code:

-- | Sets the modelview and projection matrix uniform variables.
mvpUnif :: (GL.UniformComponent a, Num a, Epsilon a, Floating a, AsUniform a) => (GLState a) -> ShaderProgram  -> IO ()
mvpUnif state p = do
-- Check if view and projection matrices are there, else set them to the identity.
let vMat = case vMatrix state of
    Just v -> v
    Nothing -> getIdentity
let pMat = case pMatrix state of
    Just p -> p
    Nothing -> getIdentity
-- Multiply model and view matrix together.
let mvMatrix = vMat !*! mMatrix state
setUniform p uModelViewMatrixVar mvMatrix
setUniform p uProjectionMatrixVar pMat

and the error:

Could not deduce (AsUniform (V4 (V4 a)))
  arising from a use of `setUniform'
from the context (GL.UniformComponent a,
                  Num a,
                  Epsilon a,
                  Floating a,
                  AsUniform a)
  bound by the type signature for
             mvpUnif :: (GL.UniformComponent a, Num a, Epsilon a, Floating a
                         AsUniform a) =>
                        GLState a -> ShaderProgram -> IO ()
  at src\Graphics\FreeD\Shaders\DefaultShaders.hs:194:12-119
In a stmt of a 'do' block:
  setUniform p uModelViewMatrixVar mvMatrix
In the expression:
  do { let vMat = ...;
       let pMat = ...;
       let mvMatrix = vMat !*! mMatrix state;
       setUniform p uModelViewMatrixVar mvMatrix;
       .... }
In an equation for `mvpUnif':
    mvpUnif state p
      = do { let vMat = ...;
             let pMat = ...;
             let mvMatrix = ...;
             .... }

V4 is made an instance of AsUniform, as well as M44, which is a type for (V4 (V4 a)), which I thought might be the issue, so I'm not sure why it's acting up.

Here's the source for the class:



Try adding -XFlexibleContexts and the constraint, literally, to your existing answer:

{-# LANGUAGE FlexibleContexts #-}

mvpUnif :: ( GL.UniformComponent a
           , Num a
           , Epsilon a
           , Floating a
           , AsUniform a
           , AsUniform (V4 (V4 a))
           ) => (GLState a) -> ShaderProgram  -> IO ()

Usually this is the routine for constraints that aren't inferrable, or where constraints need to be transitively included in all call sites. This happens to me all the time with MonadState et al. In this case, setUniform is the culprit.


Haskell IO - read from standard input directly to list

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...

Stopping condition on a recursive function - Haskell

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...

SigninActivity is not an enclosing class

I'm trying to change the activity on "onPostExecute" but it doesn't seem to work even though it works on other activities. Here's my code: public class SigninActivity extends AsyncTask<String,Void,String>{ private TextView statusField,roleField; private Context context; private int byGetOrPost = 0; public SigninActivity(Context context,TextView statusField,TextView roleField,int flag) { this.context = context;...

How to share an instance created in main with a class in another module

I am having a problem with how to share a class instance between modules. Below is not the actual code, it is a simplified representation of what I'm trying to do. The variable in question is thePlot. If I make it a global, I get 'global name not defined' type...

My simple php class not working [closed]

I wrote a simple class. but its not working. Something is wrong. can't find error line class Host { public $scheme; public $hostname; public $www; function __construct(string $scheme,string $hostname,string $www) { $this->scheme = $scheme; $this->hostname = $hostname; $this->www = $www; } public function get_URL() { return $this->scheme.'://'.$this->www.$this->hostname; } } $site...

Haskell return lazy string from file IO

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...

Haskell - generate and use the same random list

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?...

issues with installing newer cabal version for haskell vim now

I would like to install this vim plugin: When trying to run the suggested installation script: curl -o - | 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-$ ./ The response I get:...

Method nonvisibility of same instanceof but differing class

I have something like the below: Item var; Depending on user input, it will be initialized as a different class: if (/*user input*/ == 1) { var = new Item(); } else { var = new Truck(); } The classes are defined as: public class Truck extends Item { public...

apply a transformation with function inline

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...

jQuery create a real-time array from multiple inputs with the same class

I have multiple inputs on a page that all have the same class name authority-email. Using jQuery I get the values from all the inputs using the following: var emailObj = {}; $("input[class=authority-email]").each(function () { var email = $(this).val() emailObj = email; console.log(emailObj); }); These inputs can be removed and...

How to “wrap” monadic return value

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...

ToInt32() conversion [on hold]

Like ToStr() method, I am trying to convert to Int32() as following: class customer { public int ID { get; set; } public string Name { get; set; } public override int ToInt32() { return this.ID; } } Compiler is complaining about ToInt32() as no suitable method to override. Help?...

Keep track of loop without a counter

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...

logical expression evaluator 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 ::...

Interpreting hex dump of java class file

I understand the structure of a java .class file, but when I want to interpret the raw hex data I get a bit lost. This is a hex dump of a class file, excluding the header and constant pool. I understand the header to be the magic number, minor_version and...

Are interfaces a valid substitute for utility classes in Java 8? [duplicate]

This question already has an answer here: Java 8: Interface with static methods instead of static util class 4 answers For the past decade or so, I've been using the pattern below for my Java utility classes. The class contains only static methods and fields, is declared final so...

Python class design: explicit keyword arguments vs. **kwargs vs. @property

Is there a generally accepted best practice for creating a class whose instances will have many (non-defaultable) variables? For example, by explicit arguments: class Circle(object): def __init__(self,x,y,radius): self.x = x self.y = y self.radius = radius using **kwargs: class Circle(object): def __init__(self, **kwargs): if 'x' in kwargs: self.x = kwargs['x']...

Is a Java class variable a reference to a class object?

I know such question has been asked before but I couldn't find a satisfactory answer. Assume a java class : class Foo{ public int k; Foo(int a){ k=a; } } class My{ public static void main(String args[]){ Foo obj = new Foo(5);//1 obj=new Foo(8); //2 } } I want to...

Idiomatic list construction

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...

Do scala classes have “self” like Python?

For example if I have object Solution { class myClass(A: Array[Int]){ val something: Int = A.length; val another: Int = something/2; val someName = "blah" ... ... Do these variables "exist" only for a particular instance of myClass or are they "class-wide" variables shared among all objects? If it's the...

Hook into GHC runtime system

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...

Fighter class does not implement interface member

And I am getting this error: Error 1 'Fight.Fighter' does not implement interface member 'Fight.IFighter.Utok(Fight.IFighter)' This is the first time I am trying to learn working with interfaces, so sorry for dump question. Any ideas? I have following code: Interface: interface IFighter { string GraphicLife(); bool IsLive(); int Obrana(int utocneCislo);...

React components as plain JS objects?

Does anybody has experience in working with React components as plain JS objects instead of annoying ES6 classes and deprecated .createClass method. Maybe you have some examples of factory functions or similar to share? Thanks!...

Decremented value called in the recursion in Haskell

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....

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

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...

Fold over a heterogeneous, compile time, list

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...

Implementing map on a tree using fold

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 _ =...

Combining Event and an attribute in 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...

IO Monad Example

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...

First three items of a list in 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...

Laravel5: Access public variable in another class

I have a middleware file called LanguageMiddleware.php: ... class LanguageMiddleware { //ISO language codes: public $languages = ['en','es','fr','de','pt','pl','zh','ja']; ... LanguageMiddleware.php is in laravelProj/app/Http/Middleware/ Here's my problem: I have a blade template file called master.blade.php where I'm attempting to output a list of languages @foreach (App\Http\Middleware\LanguageMiddleware\languages as $lang) <a class=\"setLang\" href=\"lang/en\">{{...

Java immutability when defining members in a function called by constructor

I have class like this: abstract class Parent { protected Parent(Raw rawData) { deserialize(rawData); } protected abstract void deserialize(Raw rawData); } class Child extends Parent { final byte firstByte; public Child(Raw rawdData) { super(rawData); } protected void deserialize(Raw rawData) { firstByte = rawData.getFirst(); } } So basically any child class...

Get each fibbonacci value in haskell

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...

Global class comparison with inheritance

I am writing global class comparison functions with operator== for a large framework where classes tend to inherit several classes or have deep inheritance (class A inherits from B, B inherits from C, etc.). In order to make things manageable I figured I would have a comparison functions for base...

Downcasting doesn't work and functions called from object own class instead of where the function is (Java)

i have this classes hierarchy: public class Musician { private String name; public String instrument; public Musician(String name, String instrument) { = name; this.instrument = instrument; } public String getName() { return name; } public String getInstrument() { return instrument; } private String getClassName() { return "Musician"; } public...

Thread blocked indefinitely in an MVar operation

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...

Haskell make recipe fails for Paradox theorem prover using GHC

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...

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

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...

Issues with Array calling on classes

Day two of my journey into the world of java and I have seem to run into a road block even after scouring this wonderfully helpful website. So precontexual 411: I want an array of an unknown length to create its entries by calling on classes. I have the strangest...

Call known function (with parameters) in class whose name is defined by string variable

I have a bunch of classes of various names and each has a performLogic function that accepts a number of preset parameters (always the same): public final class DoSomeAction extends SetupAction { public void performLogic(param1, param2... I want a way where I can call it like this: String actionName =...

Haskell do clause with multiple monad types

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:...

How does Frege generalize number literals?

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...

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

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...

How return ID or all from another class with Entity Framework?

I learning Entity Framework, so don't blame me if this is easy for you I have class HomeNumber.cs [ScaffoldColumn(false)] [Key] public int HomeNumberId { get; set; } //[ForeignKey("HomeNumberId")] //public virtual HomeNumber HomeNumbers { get; set; } [Required(ErrorMessage = "Polje kućni broj je obavezno!")] public string HomeNumberName { get; set; }...

When to use pointer member variables?

I realize this is a very basic question but I'd like to see an example of when I should be setting some of my class member variables as pointers. I saw this class definition: template<class T> class Node { public: T data; Node<T> * next; Node<T>(const T& d):data(d), next() {}...

How do I avoid writing this type of Haskell boilerplate code

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...

In Java, How do I cast a Realm Object into the class I wish to write to the Database?

I am currently working on a project where my Database has a very large number of tables (Approx 60 total). I am working to create the Database Helper class that will function as the writer/ reader to/ from the database. And example of my write method would be this: public...

Silex namespace : class MainController does not exist

I try to use Silex Framework, but i have a problem with namespaces I think. when I instanciate my class MainController i have the following error : Class "MainController" does not exist here the namespace declaration in my MainController.php : namespace App\Controllers; use Silex\Application; class MainController implements \Silex\ControllerProviderInterface { .......

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

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...