Questions tagged [functional-dependencies]

A functional dependency is a constraint between two sets of attributes in a relation, in relational algebra, databases and type systems.

Functional dependencies (FD) are fundamental to the process of normalization.

Given a relation R, a set of attributes X in R is said to functionally determine a set of attributes Y, also in R, (written X → Y) if, and only if, whenever two tuples coincide on all attributes of X, they also coincide on all attributes of Y. Sound, complete and non-redundant axiomatisation of functional dependencies is given by Armstrong rules. Functional dependencies are also used in the Haskell programming language to describe relations between types, to support type level relational programming.

In other words, a dependency FD: X → Y means that the values of Y are determined by the values of X. Two tuples sharing the same values of X will necessarily have the same values of Y.

Enter image description here

544 questions
11
votes
2 answers

Typeclass instance with functional dependencies doesn't work

Playing around with type-classes I came up with the seemingly innocent class Pair p a | p -> a where one :: p -> a two :: p -> a This seems to work fine, e.g. instance Pair [a] a where one [x,_] = x two [_,y] = y However I run in trouble…
Landei
  • 54,104
  • 13
  • 100
  • 195
10
votes
2 answers

Why does this Haskell code typecheck with fundeps but produce an untouchable error with type families?

Given some type definitions: data A data B (f :: * -> *) data X (k :: *) …and this typeclass: class C k a | k -> a …these (highly contrived for the purposes of a minimal example) function definitions typecheck: f :: forall f. (forall k. (C k (B…
Alexis King
  • 43,109
  • 15
  • 131
  • 205
10
votes
2 answers

Finding candidate keys for given relation

R = (A, B, C, D, E) The functional dependencies are: A -> B ED -> A BC -> E It then lists the candidate keys as: ACD, BCD, CDE How are these candidate keys derived from the above FDs? Similarly, R = (A, B, C, D) The functional dependencies…
mickm
  • 281
  • 2
  • 6
  • 20
9
votes
2 answers

Shortening code by exploiting symmetry among multiple type class instances

Context I'm writing a Haskell module that represents SI prefixes: module Unit.SI.Prefix where Each SI prefix has a corresponding data type: data Kilo = Kilo deriving Show data Mega = Mega deriving Show data Giga = Giga deriving Show data Tera =…
9
votes
1 answer

Creating a completely dependent concatenation

A nice true fact about concatenation is that if I know any two variables in the equation: a ++ b = c Then I know the third. I would like to capture this idea in my own concat so I use a functional dependency. {-# Language DataKinds, GADTs,…
9
votes
2 answers

Why does my functional dependency conflict disappear when I expand the definition?

I was trying to implement Integers at the type level in Haskell. To start I implemented natural numbers with data Zero data Succ a I then extended this to the integers with data NegSucc a I decided to then create an Increment class that would…
9
votes
8 answers

What kind of normalization rule does this violate?

Suppose I have two tables on a database, T10 and T11, having 10 and 11 columns, respectively, where 10 of the columns are exactly the same on both. What (if any) normalization rule am I violating?
8
votes
3 answers

Bidirectional Functional Dependencies

I have a type class that looks a bit like the following: class Foo a b | a -> b where f :: a -> Bool g :: b -> Bool h :: a -> b -> Bool Or at least these are the bits that are important to my question. This class does not compile, and for…
8
votes
1 answer

Functional Dependency in Haskell

I cannot really get it. Why do we need it at all? I mean if I use the same type parameter, I think that means they should be the same type. I heard it can help the compiler to avoid the infinite loop. Can someone tell me some more details about…
aXqd
  • 733
  • 5
  • 17
8
votes
3 answers

tdd - creating tests for 3rd party code

How do I create unit tests if the method or procedure I'm testing against relies on a piece of code from a 3rd party? Say, I have a method that uses classes from a third party source that requires setup that can only be done in a functional test.…
8
votes
2 answers

Finding a relation in 3NF but not in BCNF

I've been reading many different sources on how to differentiate relations that are in 3NF/BCNF. And I've so far this is my understanding... I will use this relation as an example... R = {A, B, C, D, E} and F = {A -> B, B C - > E, E D ->…
Ogen
  • 6,499
  • 7
  • 58
  • 124
8
votes
3 answers

Lossless Join and Decomposition From Functional Dependencies

Suppose the relation R( K, L, M, N, P), and the functional dependencies that hold on R are: - L -> P - MP -> K - KM -> P - LM -> N Suppose we decompose it into 3 relations as follows: - R1(K, L, M) - R2(L, M, N) - R3(K, M, P) How can we…
8
votes
1 answer

Motivation of having Functional Dependencies

What is the motivation of having functional dependencies in Haskell ? One example of a functional dependency: class (Monad m) => MonadSupply s m | m -> s where next :: m (Maybe s) It is stated in the RWH book, that functional dependency helps the…
Sibi
  • 47,472
  • 16
  • 95
  • 163
8
votes
3 answers

Are determinants and candidate keys the same?

At https://web.archive.org/web/20130514174856/http://databases.about.com/cs/specificproducts/g/determinant.htm I found this by Mike Chapple: Definition: A determinant in a database table is any attribute that you can use to determine the values…
Aparan
  • 1,263
  • 3
  • 12
  • 17
8
votes
2 answers

What is the "coverage condition"?

The source for the State transformer in mtl states: -- --------------------------------------------------------------------------- -- Instances for other mtl transformers -- -- All of these instances need UndecidableInstances, -- because they do not…
Dan Burton
  • 53,238
  • 27
  • 117
  • 198
1
2
3
36 37