problem about functional-dependencies-Collection of common programming errors

  • Daniel Lyons
    haskell random functional-dependencies type-families
    I’m trying to implement a Fisher-Yates shuffle of some data. This algorithm is easy to implement for one-dimensional arrays. However, I need to be able to shuffle data in a two-dimensional matrix.An approach which I think could generalize nicely to higher dimensional arrays is to convert my arbitrarily dimensioned matrix to a single-dimensional array of indices, shuffle those, and then reorganize the matrix by swapping the element at each index of this index array with the element at the index of the element of the index array. In other words, to take a 2×2 matrix such as:1 2 3 4I would convert this into this “array”:[(0, (0,0)), (1, (0,1)), (2, ((1,0)), (3, (1,1))]This I would then scramble per normal int

  • KennyTM
    haskell types functional-programming type-inference functional-dependencies
    Consider the code below : {-# LANGUAGE MultiParamTypeClasses,FlexibleInstances,FunctionalDependencies,UndecidableInstances,FlexibleContexts #-} class Foo a c | a -> c instance Foo Int Float f :: (Foo Int a) => Int -> a f = undefinedNow when I see the inferred type of f in ghci > :t f > f :: Int -> FloatNow If I add the following code g :: Int -> Float g = undefined h :: (Foo Int a) => Int -> a h = gI get the error Could

  • TorosFanny
    haskell types parameters functional-dependencies
    I can tell the number of parameters of a function with the following code{-#Language MultiParamTypeClasses#-} {-#Language FunctionalDependencies#-} {-#Language UndecidableInstances#-}data Zero data Succ aclass Number a instance Number Zero instance (Number a) => Number (Succ a)class NotFunction a instance NotFunction Int instance NotFunction Float instance NotFunction (

Originally posted 2013-11-09 19:44:21.