Send Beginners mailing list submissions to
        beginners@haskell.org

To subscribe or unsubscribe via the World Wide Web, visit
        http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
        beginners-requ...@haskell.org

You can reach the person managing the list at
        beginners-ow...@haskell.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1. Re:  Functor instance for ordered lists (martin)
   2. Re:  Functor instance for ordered lists (Marcin Mrotek)
   3. Re:  infinite type (Julian Rohrhuber)
   4. Re:  Tree-like Structure with unique elements on each level
      (Stephen Tetley)
   5. Re:  Functor instance for ordered lists (Imants Cekusins)
   6. Re:  Functor instance for ordered lists (martin)
   7. Re:  Functor instance for ordered lists (Imants Cekusins)
   8. Re:  Ambiguous module name `Prelude': it was found in
      multiple packages (trying to install HXQ) (Imants Cekusins)


----------------------------------------------------------------------

Message: 1
Date: Mon, 4 Jan 2016 17:18:16 +0100
From: martin <martin.drautzb...@web.de>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <beginners@haskell.org>
Subject: Re: [Haskell-beginners] Functor instance for ordered lists
Message-ID: <568a9b48.8060...@web.de>
Content-Type: text/plain; charset=windows-1252

Am 01/04/2016 um 03:53 PM schrieb Imants Cekusins:
>> is it impossible to write a functor instance for ordered lists?
> 
> is such specialized functor instance necessary?
> 
> I mean, why not fmap over unconstrained list and init OrdList before
> passing it to a fun where sorted list is really essential?
> 
> this would eliminate the need to maintain sorted order at every step
> in list processing.
> 
> This way, OrdList type would ensure that sort-critical consumer fun
> gets a sorted list, and every other fun - fmap or not - would not
> care.

I see.

The reason why I am asking is I tried to model a predicate on nested items and 
I came up with this:

data Product a = Prod (a -> Maybe (Product a)) | Pany

The idea was that given an Item a, a Product would return Nothing if the 
toplevel Item (the "container") does not
statisfy the predicate. Otherwise it returns Just a new Product which captures 
the condition which each of the contained
items must satisfy.

That alone did not buy me much, particularly becuase I needed a way to "show" a 
product. So I needed a showable data
structure, which can be used like a Product, i.e. which can be converted into a 
Product. I came up with

data  MP a = MPacked  (M.Map a (MP a)) | MPany deriving (Show)

Then I tried to define a Functor instance and failed for the afforementioned 
reasons: a Map needs Ord keys. I found this
puzzling because a Functor on Product makes perfect sense to me.

I assume, this is because M.Map is implemented in such a way, that Ord a is 
required. Had I used a List of Pairs instead
of a Map, then no Ord constraint would have been required.

Does this make some sense?




------------------------------

Message: 2
Date: Mon, 4 Jan 2016 17:33:10 +0100
From: Marcin Mrotek <marcin.jan.mro...@gmail.com>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <beginners@haskell.org>
Subject: Re: [Haskell-beginners] Functor instance for ordered lists
Message-ID:
        <CAJcfPznUGMc0PBdg_Di4_n47veF-TEZtF=l4a10hm--6yie...@mail.gmail.com>
Content-Type: text/plain; charset=UTF-8

> would certainly require an Ord constraint on a, but where would I put it? I 
> can put it on all the functions manipulating
> OrdLists, but I still wouldn't know how to define a functor instance, because 
> a Functor a does not require Ord a.

It's of questionable utility, as it still doesn't let you define a
Functor instance (and can no longer be a newtype), but if you want,
you can use a GADT:

data OrdList a where
   OrdList :: Ord a => a -> OrdList a

Best regards
Marcin Mrotek


------------------------------

Message: 3
Date: Mon, 04 Jan 2016 16:59:17 +0100
From: Julian Rohrhuber <julian.rohrhu...@musikundmedien.net>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <beginners@haskell.org>
Subject: Re: [Haskell-beginners] infinite type
Message-ID: <0de673f7-b0f5-4fd8-8e82-3591eff0b...@musikundmedien.net>
Content-Type: text/plain; charset="us-ascii"

An HTML attachment was scrubbed...
URL: 
<http://mail.haskell.org/pipermail/beginners/attachments/20160104/9cd1a6af/attachment-0001.html>

------------------------------

Message: 4
Date: Mon, 4 Jan 2016 17:51:57 +0000
From: Stephen Tetley <stephen.tet...@gmail.com>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <beginners@haskell.org>
Subject: Re: [Haskell-beginners] Tree-like Structure with unique
        elements on each level
Message-ID:
        <CAB2TPRC=i2ex5w94ccm-mooy2npr5lef8_ycb+nzbjyet+p...@mail.gmail.com>
Content-Type: text/plain; charset=UTF-8

Hi Martin

The essence of a trie data structure is that all keys at each level
are unique, so so lookup in a trie forms a search path.

There are various implementations of tries on Hackage.

Best wishes

Stephen

On 2 January 2016 at 19:53, martin <martin.drautzb...@web.de> wrote:
> Hello all,
>
> I recently modeled a tree like this:
>
> data Predicate a = Any | Pred (S.Set a)
> data Product a = Pany | Prod (S.Set(Predicate a, S.Set(Product a)))
>
> What I wanted to achieve was to have each element only once on each level. 
> Hence the Sets. But this structure does not
> achieve this. I can easily duplicate elements on a level as long as their 
> subordinates are different, so I might as well
> give up working with sets.
>
> Is there a way to construct a tree where each element can occur only once on 
> each level?
> _______________________________________________
> Beginners mailing list
> Beginners@haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners


------------------------------

Message: 5
Date: Mon, 4 Jan 2016 22:11:28 +0100
From: Imants Cekusins <ima...@gmail.com>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <beginners@haskell.org>
Subject: Re: [Haskell-beginners] Functor instance for ordered lists
Message-ID:
        <cap1qinymcwdb0ztjxebhcc5zh_sxy1wnp+iu5xazjsfrriy...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

Is predicate a function specific to each product, used to compose product?

Or is it used when querying products to filter them?

I'd define data structures as records, sometimes with a couple variable
types. Then if variable types are used, define classes to query, modify
data.

Why not define product as
data Prod a c = Prod a [c]

where a is product info and c is child item data.

Then define predicate class.

Then define a's and c's separately for each use case. Maybe add types for
each specific product.

Then add instances.

This way future changes will be easy. It is easier to work on specifics
when generics are simple. Specific products may be as complex as necessary.

If you define product as a complex type with a few type variables, changes
will be more difficult.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://mail.haskell.org/pipermail/beginners/attachments/20160104/32545bcd/attachment-0001.html>

------------------------------

Message: 6
Date: Mon, 4 Jan 2016 22:54:37 +0100
From: martin <martin.drautzb...@web.de>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <beginners@haskell.org>
Subject: Re: [Haskell-beginners] Functor instance for ordered lists
Message-ID: <568aea1d.5070...@web.de>
Content-Type: text/plain; charset=windows-1252

Am 01/04/2016 um 10:11 PM schrieb Imants Cekusins:


> Why not define product as
> data Prod a c = Prod a [c]
> 
> where a is product info and c is child item data.

Well first the Product is not necessarily a single "thing". There can be 
various a's which satisfy the criteria to fall
into a specific Product. So either a must be a set-like thing or a function 
a->Bool.

Then there is not necessarily just one level of nesting. The c's can still be 
containers, and it matters what's inside
them. It's like a carton of iPhones, which has iPhone packages inside and each 
iPhone package consists of an iPhone, a
Charger, a Manual and ... and the Charger consists of a Cable, a circuit board 
...

If any of the conditions are not met, if e.g. you receive a carton of iPhones 
where one charger lacks its cable, you
have reason to complain.



------------------------------

Message: 7
Date: Mon, 4 Jan 2016 23:01:30 +0100
From: Imants Cekusins <ima...@gmail.com>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <beginners@haskell.org>
Subject: Re: [Haskell-beginners] Functor instance for ordered lists
Message-ID:
        <CAP1qinYjPHL8UOQqScCavoUf=+QWq3vZY1vzC=5ojo3xbf0...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

a and c can be anything: function, algebraic type, ...

That's the thing. Prod a [c] leaves plenty of room.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://mail.haskell.org/pipermail/beginners/attachments/20160104/1ad06dda/attachment-0001.html>

------------------------------

Message: 8
Date: Tue, 5 Jan 2016 00:50:57 +0100
From: Imants Cekusins <ima...@gmail.com>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <beginners@haskell.org>
Subject: Re: [Haskell-beginners] Ambiguous module name `Prelude': it
        was found in multiple packages (trying to install HXQ)
Message-ID:
        <cap1qinatdrhznzjj4pe+5kkwsb3_e0mtfwosj-9yz+ty57g...@mail.gmail.com>
Content-Type: text/plain; charset=UTF-8

> Ambiguous module name `Prelude':
      it was found in multiple packages: base haskell98-2.0.0.2

just guessing:

https://hackage.haskell.org/package/HXQ
-> https://hackage.haskell.org/package/haskell98
->  base (==4.7.*),

what base version was installed on your pc before you tried to install HXQ?

is it possible to install multiple base versions?


------------------------------

Subject: Digest Footer

_______________________________________________
Beginners mailing list
Beginners@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners


------------------------------

End of Beginners Digest, Vol 91, Issue 7
****************************************

Reply via email to