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 (Benjamin Edwards)
   3. Re:  Functor instance for ordered lists (Benjamin Edwards)
   4. Re:  Functor instance for ordered lists (Imants Cekusins)
   5. Re:  Functor instance for ordered lists (Imants Cekusins)
   6.  Ambiguous module name `Prelude': it was found in multiple
      packages (trying to install HXQ) (Stanislaw Findeisen)
   7. Re:  infinite type (Julian Rohrhuber)


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

Message: 1
Date: Mon, 4 Jan 2016 15:26:19 +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: <568a810b.8010...@web.de>
Content-Type: text/plain; charset=windows-1252

Am 01/04/2016 um 11:45 AM schrieb Imants Cekusins:
>> a newtype for ordered lists
> 
> why not:
> newtype Ordlist a = Ordlist [a]

All nice and dandy, but at first you already need an Ord constraint for your 
smart constructor

-- and a ctor:
ordList::(Ord a) => [a]-> OrdList a
ordList = OrdList . sort

but this is still not the main problem. When you try to define a Functor 
instance, you'd be tempted to do this (at least
I was):

instance Functor OrdList where
        fmap f (OrdList xs) = OrdList $ sort $ map f xs

but you can't do this, because of: "No instance for (Ord b) arising from a use 
of ?sort?", where b is the return type of
f :: (a->b). This does make sense, the function has to return something which 
can be sorted.

So my question is: is it impossible to write a functor instance for ordered 
lists? It appears so, because a Functor does
not impose any constraints of f. But my knowledge is quite limited and maybe a 
well-set class constraint can fix things.




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

Message: 2
Date: Mon, 04 Jan 2016 14:46:20 +0000
From: Benjamin Edwards <edwards.b...@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:
        <CAN6k4njw8foC=pp2+aftyouxnoua76hu2q9spb7gs+akp5m...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

It is impossible.

You can make a new functor class using contraint kinds that allows what you
want. There is probably a package out there already that does!

http://www.cl.cam.ac.uk/~dao29/publ/constraint-families.pdf

Sections 2.2 and 5.1 have the relevant stuff. I realise this is a bit err,
dense for the beginners list. There are probably better references out
there.

Ben

On Mon, 4 Jan 2016 at 14:30 martin <martin.drautzb...@web.de> wrote:

> Am 01/04/2016 um 11:45 AM schrieb Imants Cekusins:
> >> a newtype for ordered lists
> >
> > why not:
> > newtype Ordlist a = Ordlist [a]
>
> All nice and dandy, but at first you already need an Ord constraint for
> your smart constructor
>
> -- and a ctor:
> ordList::(Ord a) => [a]-> OrdList a
> ordList = OrdList . sort
>
> but this is still not the main problem. When you try to define a Functor
> instance, you'd be tempted to do this (at least
> I was):
>
> instance Functor OrdList where
>         fmap f (OrdList xs) = OrdList $ sort $ map f xs
>
> but you can't do this, because of: "No instance for (Ord b) arising from a
> use of ?sort?", where b is the return type of
> f :: (a->b). This does make sense, the function has to return something
> which can be sorted.
>
> So my question is: is it impossible to write a functor instance for
> ordered lists? It appears so, because a Functor does
> not impose any constraints of f. But my knowledge is quite limited and
> maybe a well-set class constraint can fix things.
>
>
> _______________________________________________
> Beginners mailing list
> Beginners@haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://mail.haskell.org/pipermail/beginners/attachments/20160104/eeb19714/attachment-0001.html>

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

Message: 3
Date: Mon, 04 Jan 2016 14:49:38 +0000
From: Benjamin Edwards <edwards.b...@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:
        <CAN6k4ngZ+rueAOzpOvX-fmvx4RPB--6131q8Qyiz_Hiocg=b...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

This is a bit better:
https://dorchard.wordpress.com/2011/10/18/subcategories-in-haskell-exofunctors/

On Mon, 4 Jan 2016 at 14:46 Benjamin Edwards <edwards.b...@gmail.com> wrote:

> It is impossible.
>
> You can make a new functor class using contraint kinds that allows what
> you want. There is probably a package out there already that does!
>
> http://www.cl.cam.ac.uk/~dao29/publ/constraint-families.pdf
>
> Sections 2.2 and 5.1 have the relevant stuff. I realise this is a bit err,
> dense for the beginners list. There are probably better references out
> there.
>
> Ben
>
> On Mon, 4 Jan 2016 at 14:30 martin <martin.drautzb...@web.de> wrote:
>
>> Am 01/04/2016 um 11:45 AM schrieb Imants Cekusins:
>> >> a newtype for ordered lists
>> >
>> > why not:
>> > newtype Ordlist a = Ordlist [a]
>>
>> All nice and dandy, but at first you already need an Ord constraint for
>> your smart constructor
>>
>> -- and a ctor:
>> ordList::(Ord a) => [a]-> OrdList a
>> ordList = OrdList . sort
>>
>> but this is still not the main problem. When you try to define a Functor
>> instance, you'd be tempted to do this (at least
>> I was):
>>
>> instance Functor OrdList where
>>         fmap f (OrdList xs) = OrdList $ sort $ map f xs
>>
>> but you can't do this, because of: "No instance for (Ord b) arising from
>> a use of ?sort?", where b is the return type of
>> f :: (a->b). This does make sense, the function has to return something
>> which can be sorted.
>>
>> So my question is: is it impossible to write a functor instance for
>> ordered lists? It appears so, because a Functor does
>> not impose any constraints of f. But my knowledge is quite limited and
>> maybe a well-set class constraint can fix things.
>>
>>
>> _______________________________________________
>> Beginners mailing list
>> Beginners@haskell.org
>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://mail.haskell.org/pipermail/beginners/attachments/20160104/ce0c140a/attachment-0001.html>

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

Message: 4
Date: Mon, 4 Jan 2016 15:53:34 +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:
        <cap1qinbhvv-kkfsvuonhk5kkr69wsdlucutwlcpnl8qmi1c...@mail.gmail.com>
Content-Type: text/plain; charset=UTF-8

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


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

Message: 5
Date: Mon, 4 Jan 2016 16:21:46 +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:
        <cap1qinymcnpoecac-f7ypvnmukmpttjqiuhspt6d57eefny...@mail.gmail.com>
Content-Type: text/plain; charset=UTF-8

> Functor does not impose any constraints of f.

it seems so. I ran into this too. not that i wrote many functor
instances but I could not figure out how to add (any kind of)
constraint to a functor.

Ben already wrote about this  - if I understand him correctly.


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

Message: 6
Date: Mon, 4 Jan 2016 16:59:13 +0100
From: Stanislaw Findeisen <waka.2...@eisenbits.com>
To: beginners@haskell.org
Subject: [Haskell-beginners] Ambiguous module name `Prelude': it was
        found in multiple packages (trying to install HXQ)
Message-ID: <568a96d1.8050...@eisenbits.com>
Content-Type: text/plain; charset=utf-8; format=flowed

Hi!

I am trying to install HXQ: https://hackage.haskell.org/package/HXQ . 
But somehow it doesn't work:

$ cabal install hxq
Resolving dependencies...
Configuring HXQ-0.19.0...
Building HXQ-0.19.0...
Failed to install HXQ-0.19.0
Build log ( /home/ct/.cabal/logs/HXQ-0.19.0.log ):
Configuring HXQ-0.19.0...
Building HXQ-0.19.0...
Preprocessing library HXQ-0.19.0...

src/Text/XML/HXQ/XQuery.hs:1:1:
     Ambiguous module name `Prelude':
       it was found in multiple packages: base haskell98-2.0.0.2
cabal: Error: some packages failed to install:
HXQ-0.19.0 failed during the building phase. The exception was:
ExitFailure 1

Why?

Thanks!

-- 
http://people.eisenbits.com/~stf/
http://www.eisenbits.com/

OpenPGP: 9EC2 5620 2355 B1DC 4A8F  8C79 0EC7 C214 E5AE 3B4E


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

Message: 7
Date: Mon, 04 Jan 2016 16:59:26 +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: <ece3db63-357b-4d28-8963-01a7d3a05...@musikundmedien.net>
Content-Type: text/plain; charset=utf-8


> On 03.01.2016, at 22:30, Theodore Lief Gannon <tan...@gmail.com> wrote:
> 
>    sum :: Num a => a -> (a -> a)
>    f :: (a -> a) -> (a -> a)
> 
> To really drive it home, let's play with synonyms.
> 
>    type Endo' a = (a -> a)
> 
> Endo already exists as a newtype in Data.Monoid, thus Endo' here. Now:
> 
>    sum :: Num a => a -> Endo' a
>    f :: Endo' a -> Endo? a

ok, this makes sense to me now ? thank you very much for your patience. I?m 
trying to make the conclusion explicit, so please correct me if I?m wrong.

if type checking of "f sum" assumes the type variable "a" to be of type Endo' 
in f, it concludes: 

sum takes Endo' to Endo' Endo'

which looks equivalent to trying to construct an infinite type.

The type checker seems not to worry about the more obvious arity/Num 
restriction of sum, which makes the result more interesting.

More generally, if 

1) f is a function that maps a function to a function of the same type (a -> a) 
-> (a -> a)
2) sum is a function that maps a value of type b to a function from (b -> b)
3) then their composition ?f sum? would have two constraints: 
        sum maps value a into function b = (a -> a)
        but f assumes equality between a and b, 
        so that the required type would be one where a = (a -> a).

which is possibly inconsistent, e.g. when it is interpreted as a definition of 
a set which has as its elements all sets of pairs of elements of that same set.


> On 03.01.2016, at 22:50, Imants Cekusins <ima...@gmail.com> wrote:
> Could you think of a useful practical example of 
> 
> (a->a->a) . (a->a->a)


Good question. I indeed had nothing else in mind but to reason about functions. 
Which is quite practical if you are trying to understand haskell!

I could imagine useful variants of function application, but that is pure 
speculation.





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

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 6
****************************************

Reply via email to