Entity instance of Ord

22 views
Skip to first unread message

geoff

unread,
May 30, 2012, 5:21:05 PM5/30/12
to yeso...@googlegroups.com
I have been trying to ask in IRC but my internet connection has been so shotty I am missing replies and failing silently.

Anyway, I am pretty sure this code will 'smell very bad' ; but I also believe it would do what I wanted it to do if Entity was an instance of Ord.

I don't actually care what they are ordered by so long as it is consistent, so I thought of just making sure Entity was ordering by the key.

Is this bad?


and a synopsis of what I am trying to do:

I have two lists of tuples, specifically a [(Entity Player,[Entity GamingSessions])] and a [(Entity Player,[Entity ManualSession])]

What I want out of it all is a 7 tuple for being consumed by a hamlet file:

[(Entity Player, [Entity GamingSession], [Entity ManualSession], EarnedMinutes, EarnedPoints, GivenMinutes, GivenPoints)]

where these are all derived from the [Entity GamingSession] and [Entity ManualSession] :

type EarnedMinutes = Int
type GivenMinutes = Int
type EarnedPoints = Double
type GivenPoints = Double


The 'problem' is that the two lists don't necessarily have the same Entity Players, so I want to make a union as if Entity Player were the index.  So I wrote code to do that and called it marry' in the hpaste

The code relies on the two lists being sorted, and seeing if it should "take" from the head of: one list, the other list, or both lists-- in creating the next element of the list of 7-tuples 




Felipe Almeida Lessa

unread,
May 30, 2012, 5:24:56 PM5/30/12
to yeso...@googlegroups.com
On Wed, May 30, 2012 at 6:21 PM, geoff <geoff...@gmail.com> wrote:
> I have been trying to ask in IRC but my internet connection has been so
> shotty I am missing replies and failing silently.
>
> Anyway, I am pretty sure this code will 'smell very bad' ; but I also
> believe it would do what I wanted it to do if Entity was an instance of Ord.

Entity is an instance of Ord [1]. Maybe your entity (on your
config/models file) isn't deriving Ord?

Cheers,

[1] http://hackage.haskell.org/packages/archive/persistent/0.9.0.4/doc/html/Database-Persist-Store.html#t:Entity


--
Felipe.

geoff

unread,
May 30, 2012, 5:27:20 PM5/30/12
to yeso...@googlegroups.com
Well when I add Ord to the list of things being derived I get this new error

Model.hs:15:1:
    No instance for (Ord Textarea)
      arising from the 'deriving' clause of a data type declaration
    Possible fix:
      add an instance declaration for (Ord Textarea)
      or use a standalone 'deriving instance' declaration,
           so you can specify the instance context yourself
    When deriving the instance for (Ord (PlayerGeneric backend))
Build failure, pausing...

geoff

unread,
May 30, 2012, 5:29:29 PM5/30/12
to yeso...@googlegroups.com
^^ my config/models

Felipe Almeida Lessa

unread,
May 30, 2012, 5:37:44 PM5/30/12
to yeso...@googlegroups.com

As far as I know, you shouldn't save text as Textarea on your entity. Instead just use Text and wrap/unwrap the Textarea on your forms.

Cheers,

--
Felipe – enviado do meu Galaxy Tab.

Michael Snoyman

unread,
May 31, 2012, 12:26:38 AM5/31/12
to yeso...@googlegroups.com
Actually, I do think storing a Textarea in the entity has an
advantage: it means you automatically get the ToHtml instance that
adds in line breaks.

Anyway, adding an Ord instance for Textarea isn't problematic, I'll
include it in the next release of yesod-form.

Michael

geoff

unread,
May 31, 2012, 10:22:37 AM5/31/12
to yeso...@googlegroups.com
Great thanks Michael.  I pulled in your change and it works like a charm.
Reply all
Reply to author
Forward
0 new messages