Question: What help would you like?

Asked By
Asked At
2017-12-01 14:40:40

Found 15 possible answers.

User Answered At Possible Answer
kunzhou 2017-12-01 14:41:13 In the snippet type User = Anonymous | Named String , User is a union type consisting of Anonymous and Named String And sometimes we have List String , which is a List of strings? and it seems type User = Anonymous String | Named String is also valid. I don't understand why this is needed? Because both are strings already is Named String a type or constructor function?
ilias 2017-12-01 14:42:44 Named is a data constructor for the User type which carries a piece of data (a String ) So basically this means you can disambiguate between different types of user
kunzhou 2017-12-01 14:43:33 I see. Is there a OOP equivalent?
ilias 2017-12-01 14:43:39
case user of
User name -> "(verified) " ++ name Anonymous name -> "(anon) " ++ name
kunzhou 2017-12-01 14:43:43 can't wrap my head around it so string can have different types. Can we understand type as a class?
ilias 2017-12-01 14:44:38 There's no direct OOP equivalent I think. You could think of them as separate instances that carry potentially different types of data, and are tagged with something that identifies them
kunzhou 2017-12-01 14:45:10 I was thinking User is the super class, and Anonymous and Named extends from it
ilias 2017-12-01 14:45:13 String is always just a String, the type of String doesn't change. Rather, you "tag" the data
kunzhou 2017-12-01 14:45:29 And for named , it has a field String
ilias 2017-12-01 14:45:39 have you read the section on union types in the guide? ( )
kunzhou 2017-12-01 14:45:45 okay, the concept of tagging so yeah I am reading it
ilias 2017-12-01 14:45:56 I wouldn't really recommend trying to understand it in terms of OOP concepts
kunzhou 2017-12-01 14:45:58 can't wrap my head around .,.
ilias 2017-12-01 14:46:20 Sometimes they're vaguely similar but in the long run it won't help; even though it's a totally natural thing to do
nimanimanima 2017-12-01 14:46:25 Well I have the following function where the Admin.Todo.Item records contain a "reminder" field which is a Maybe Date. I'd like it to sort a list of Admin.Todo.Item with the latest "Item.reminder" dates being ordered first in the list. The Nothing dates should be last
compareReminders : List Admin.Todo.Item -> List Admin.Todo.Item
I'm a bit stuck since the above function doesn't return a record with a Maybe Date, but a Date instead.
List.sortWith compareReminders list |> List.reverse in ( Compare.After) a.reminder b.reminder compareReminders a b = let compareReminders list =

Related Questions