value-constructor

Why can't i re-use same value constructor among different data types?

有些话、适合烂在心里 提交于 2020-02-15 07:37:38
问题 i am new to Haskell and probably missing something really basic here, but i am not able to re-use same value constructor among different data types. data Colour = Red | Pink | Orange | Yellow data Fruit = Apple | Orange | Banana This produces error saying Multiple declarations of ‘Orange’ Not sure why this isn't allowed, i have been using OCaml before learning Haskell and was able to define types like this 回答1: As a quick exercise try just defining one of your data types and then opening up

Why can't i re-use same value constructor among different data types?

蹲街弑〆低调 提交于 2020-02-15 07:37:13
问题 i am new to Haskell and probably missing something really basic here, but i am not able to re-use same value constructor among different data types. data Colour = Red | Pink | Orange | Yellow data Fruit = Apple | Orange | Banana This produces error saying Multiple declarations of ‘Orange’ Not sure why this isn't allowed, i have been using OCaml before learning Haskell and was able to define types like this 回答1: As a quick exercise try just defining one of your data types and then opening up

What is the difference between value constructors and tuples?

邮差的信 提交于 2019-12-21 07:29:30
问题 It's written that Haskell tuples are simply a different syntax for algebraic data types. Similarly, there are examples of how to redefine value constructors with tuples. For example, a Tree data type in Haskell might be written as data Tree a = EmptyTree | Node a (Tree a) (Tree a) which could be converted to "tuple form" like this: data Tree a = EmptyTree | Node (a, Tree a, Tree a) What is the difference between the Node value constructor in the first example, and the actual tuple in the

What is the difference between value constructors and tuples?

落花浮王杯 提交于 2019-12-04 02:22:25
It's written that Haskell tuples are simply a different syntax for algebraic data types. Similarly, there are examples of how to redefine value constructors with tuples. For example, a Tree data type in Haskell might be written as data Tree a = EmptyTree | Node a (Tree a) (Tree a) which could be converted to "tuple form" like this: data Tree a = EmptyTree | Node (a, Tree a, Tree a) What is the difference between the Node value constructor in the first example, and the actual tuple in the second example? i.e. Node a (Tree a) (Tree a) vs. (a, Tree a, Tree a) (aside from just the syntax)? Under

Why am I able to use my value constructor even though I don't export it?

∥☆過路亽.° 提交于 2019-11-30 19:22:13
For practice, I'm implementing a queue data type in a module called "Queue". My data type is also called "Queue", as is its only value constructor: module Queue (Queue, enq, emptyQueue) where data Queue a = Queue { inbox :: [a], outbox :: [a] } deriving (Eq, Show) emptyQueue :: Queue a emptyQueue = Queue [] [] enq :: a -> Queue a -> Queue a enq x (Queue inb out) = Queue (x:inb) out -- other function definitions (irrelevant here)... As far as I understand, because I wrote Queue , not Queue(..) or Queue(Queue) in the export statement, I don't expect the value constructor of my data type to be

Why am I able to use my value constructor even though I don't export it?

半世苍凉 提交于 2019-11-30 04:15:22
问题 For practice, I'm implementing a queue data type in a module called "Queue". My data type is also called "Queue", as is its only value constructor: module Queue (Queue, enq, emptyQueue) where data Queue a = Queue { inbox :: [a], outbox :: [a] } deriving (Eq, Show) emptyQueue :: Queue a emptyQueue = Queue [] [] enq :: a -> Queue a -> Queue a enq x (Queue inb out) = Queue (x:inb) out -- other function definitions (irrelevant here)... As far as I understand, because I wrote Queue , not Queue(..)